C

@chandan1826

secondlargestno

NodeJS
1 year ago
const a = [1,3,6,9,2,4,7,9,8] let highest = a[0] let secondHighest = a[0] for(val of a){ if(val > highest){ highest = val }else if(val < highest && val > secondHighest){ secondHighest = val

occurance

NodeJS
1 year ago
const arr = [1,2,3,2,5,2,4] for (let i = 0; i < arr.length; i++) { })

output question

NodeJS
1 year ago
console.log('Start'); // 1 setTimeout(() => { console.log('setTimeout 1'); // 8 }, 0); setTimeout(() => { console.log('setTimeout 2'); // 9 }, 0);

Rotate Array

NodeJS
1 year ago
const nums = [1,2,3,4,5,6,7] const k = 2 const Output = [5,6,7,1,2,3,4] //Explanation: /* rotate 1 steps to the right: [7,1,2,3,4,5,6] rotate 2 steps to the right: [6,7,1,2,3,4,5] rotate 3 steps to the right: [5,6,7,1,2,3,4] */ function shiftArr

diffrence in arr

NodeJS
1 year ago
const findLargestDifference = (array) => { // Check if the array is empty or has only one element if (array.length < 2) { throw new Error('Array must have at least two elements to find a difference.'); } // Initialize variables to store

memized

NodeJS
1 year ago
const addSum = (a,b,c)

Flatten nested Object

NodeJS
1 year ago
const userProfile = { id: 1, name: { first: "John", last: "Doe" }, age: 30, address: { street: "123 Main St", city: "Springfield",

deepClone

NodeJS
1 year ago
const obj = {a:10,b:{d:{e:50,f:60}}} // c:[20,30,40], function clone(val){ if(typeof val === "object"){ return } } let value = Object.keys(obj).map(function abc(item){

generator

NodeJS
1 year ago
function* generatorFunction() { yield "Hello" yield "World" } const generatedValue = generatorFunction() for(const word of generatedValue){

Throttle

NodeJS
1 year ago
const throttle = (fn, wait) => { let throttled return function(){ if(!throttled){ fn.apply(this, arguments) throttled = true setTimeout(()=>{ throttled = false }, wait

debouncing

NodeJS
1 year ago
const debounce = (func, wait) => { let timmer return function(){ if(timer){ clearTimeout(timer) } timmer = setTimeout(()=>{ func.call(this, ...args) }, wait)

Curring

NodeJS
1 year ago
const sum = (a,b,c) => { return a + b + c } function currifySum(func){ return function currify(...args){ return args.length === func.length ? func.call(this, ...args):currify.bind(this, ...args) } }

Adding two value of identical keys

NodeJS
1 year ago
//Adding two value of identical keys const person = [ {"1": 1}, {"2":2}, {"1": 3} ]; const newObj = {} person.map(item=>{ for(const [key, value] of Object.entries(item)){

Anagram

NodeJS
1 year ago
let str1 = "racecar is " let str2 = "carerac is" // const isAnagram = (str1, str2) => { // if(str1.length !== str2.length){ // return false // }

Reverse entire sentance

NodeJS
1 year ago
const arr = "My name is Shweta Menon" const reverseRec = (str) =>{ if(str.length < 1) return "" return reverseRec(str.substring(1)) + str.charAt(0) } console.log(reverseRec(arr))

Reverse sentence

NodeJS
1 year ago
function reverseString(str){ let i = str.length - 1 let rverse = "" while(i >= 0){ rverse = rverse + str[i] i-- } return rverse }

Fibonacci

NodeJS
1 year ago
function fibonacci(n){ let i = 0 let prev = 0 let next = 1 while(i<n){ console.log(prev);

flaten Arr

NodeJS
1 year ago
function flatArr(arr){ let flat = [] for(let value of arr){ if(Array.isArray(value)){ flat = flatArr([...flat, ...flatArr(value)]) }else{ flat.push(value) }

Deep Clone Object

NodeJS
1 year ago
const obj = {a:10,b:{c:[20,30,40],d:{e:50,f:60}}} function deelpCloneObject(obj) { if(obj === null || typeof obj !== "object"){ return obj } if(Array.isArray(obj)){ const copyArr = [] for(let value of obj){