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...
Articles tagged with #javascript
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(() => { ...
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...
let arr = [1, 2, 3, 4, 5, 4, 3, 2, 1] let res = 0; for (let i = 0; i < arr.length; i++) { res = res ^ arr[i] } console.log(res)
//Union function union(arr1, arr2) { const arr3 = [ ...new Set([...arr1, ...arr2])] return arr3 } console.log(union(['orange', 'green', 'blue'], ['yellow', 'white', 'blue'])) function union(arr1, arr2) { const arr3 = arr1.concat(arr2) return...