Write a javascript program to extract the common elements and sort them in an ascending order.
let arr = [1,2,2,4,5,6,6,7,7] let res = arr.filter((item, index)=>arr.indexOf(item) !== index).sort((a,b)=>a-b) console.log(res)
Search for a command to run...
let arr = [1,2,2,4,5,6,6,7,7] let res = arr.filter((item, index)=>arr.indexOf(item) !== index).sort((a,b)=>a-b) console.log(res)
import { useEffect, useState } from "react"; import "./styles.css"; export default function App() { const [seconds, setSeconds] = useState(60); // Initial value is set to 60 seconds useEffect(() => { const timerId = setInterval(() => { ...
function reverseEachWord(sentence) { const words = sentence.split(' '); // Split the sentence into words const reversedWords = words.map(word => word.split('').reverse().join('')); // Reverse each word const reversedSentence = reversedW...

import { useRef } from "react"; import "./styles.css"; export default function App() { const inputRef = useRef();const handleFunction = () => { inputRef.current.focus() }return ( <div className="App"> <input ref={inputRef} type="text" /> <button onCl...
function flattenArray(arr){ let flattened = []; function flatten(ArrElem){ for(let i=0;i<ArrElem.length; i++){ if(Array.isArray(ArrElem[i])){ flatten(ArrElem[i]) } else{ flattened.push(ArrElem[i]) } } } flatten(arr) return flattened } let arr = [1, 2...
let counter = 0; function getData(){ console.log("functionc alled"); } function myDebounce(call, d){ let timer; return function(...args){ if(timer) clearTimeout(timer); setTimeout(function() { call(); }, d); } } const betterFunction = myDebounce(getD...
import "./styles.css"; import { useState } from "react"; export default function App() { const [todoList, setTodoList] = useState([]); const [input, setInput] = useState("");const addItem = (e) => { if (input.length) { const item = { id: Math.random(...
class Queue { constructor() { this.items = []; this.headIndex = 0; this.tailIndex = 0; } enqueue(element) { this.items[this.tailIndex] = element; this.tailIndex++; } dequeue() { let...
class Stack { constructor() { this.items = []; } addToStack(element) { return this.items.push(element) } removeFromStack(element) { return this.items.pop(element) } peekStack() { return thi...