C

@chandan1826

Flatten_arr

NodeJS
1 day ago
const arr = [1, [2, [3, 4]], 5]; function flattenArr(arr){ let fArr = []; for(const a of arr){ if(Array.isArray(a)){ fArr = fArr.concat(flattenArr(a)) } else{ fArr.push(a);

String_reverse

NodeJS
1 day ago
const str = "I love Angular"; function reverseSentence(str) { // let text = str.split(' '); // console.log(text); let reverseText = '' for(let i= str.length-1; i > -1; i--){ reverseText += str[i]; } return reverseTex

second_largest

NodeJS
1 day ago
const arr = [10, 20, 30, 5] function secondLargest(){ let largestNumber = 0; let secondLargest = 0; for(const num of arr){ if(num > largestNumber){ secondLargest = largestNumber; largestNumber = num

Duplicate_number

NodeJS
1 day ago
const nums = [1, 2, 3, 2, 4, 1]; function duplicateNumber(){ const count = {}; const duplicateNum = [] for (let n of nums) { count[n] = (count[n] || 0) + 1; }

Valid Parentesis

NodeJS
1 day ago
const str = '({[]})['; const pairs = { ')' : '(', '}' : '{', ']' : '[' } function isValid(str){ const stack =[];

pr1

TypeScript
1 day ago
const message:string = "hello world!"; console.log(message);

rec1_practice2

NodeJS
5 months ago
const tree = { id: 1, name: "App", children: [ { id: 2, name: "Header", children: [ { id: 3, name: "Logo" }, { id: 4, name: "Nav" }

rec1_practice

NodeJS
5 months ago
const componentTree = { id: 1, name: "App", children: [ { id: 2, name: "Header", children: [ { id: 3, name: "Logo" }, { id: 4, name: "Nav" }

sum of array recursion

NodeJS
1 year ago
const sumOfArray = (arr, i=0) => { //return arr.reduce((acc, curr) => acc+curr , 0) if(i === arr.length ){ return 0 } return arr[i] + sumOfArray(arr, i + 1)

find pair in array

NodeJS
1 year ago
// Given an array of integers, //write a JavaScript function that finds and prints //all pairs of numbers in the array that sum up to 17. //Optimize the function to have a time complexity of O(n). const newArr = [1,2,13,4,15,18,-1] const checkPa

contiguous array

NodeJS
1 year ago
// Problem statement // Given an array of numbers, find the maximum sum of any contiguous subarray of the array. // For example, given the array [34, -50, 42, 14, -5, 86], the maximum sum would be 137, since we would take elements 42, 14, -5, an

pallindrome

NodeJS
1 year ago
const isPallindrome = (str) => { let rev1 = "" let rev2 = "" let track = parseInt(str.length/2) - 1 let track2 = track+(track%2===0?2:1) for(let i = track; i > -1; i--){ rev1 = rev1 + str[i].toLowerCase()

prod-interview

NodeJS
1 year ago
const obj = { id: 1, name: "Parent", children: [ { id: 2, name: "Child 1", children: [ { id: 5,

Anagrambyownmethod

NodeJS
1 year ago
const isAnagram = (str1, str2) => { str1 = str1.replace(/[^a-z0-9]/gi, '').toLowerCase(); str2 = str2.replace(/[^a-z0-9]/gi, '').toLowerCase(); // Check if lengths match after cleaning strings if (str1.length !== str2.length) { ret

nterview1

NodeJS
1 year ago
//separate repeated characters and unique characters from an array. const input = [3,5,3,2,4,6,3,5,6,7,3,5] // output- // [2,4,7] // [3,5,6] const extract = (arr) => {

int6aug

NodeJS
1 year ago
const arr = [1,2,4,5,5,2,6,7] const findUniqueElem = (arr) => { const obj = {} for(value of arr){ if(obj[value]){ delete obj[value] }else{ obj[value] = true }

mergearrays

NodeJS
1 year ago
const arr1 = [1,2,3,4] const arr2 = [5,6,7] // arr1.push(...arr2) console.log(arr1) function mergeArrays(array1, array2) { const mergedArray = []; const maxLength = Math.max(array1.length, array2.length);

turing interview

NodeJS
1 year ago
// Write a function that takes an array of integers and an integer k, and returns the maximum sum of any contiguous subarray of length k. /* Test cases arr: [1, 4, 2, 10, 23, 3, 1, 0, 20], k: 4, expected: 39 }, Subarray [10, 23, 3, 1] arr: [2, 1,

substring

NodeJS
1 year ago
const s1 = "abcabcbb"; const s2 = "bbbbb"; const s3 = "pwwkew"; const s4 = "abcdefg"; const checkIfCharExist = (str, char) => { let repeat = false for(val of str){ if(val === char){

practice1

NodeJS
1 year ago
const input = ["a1b2", "c3d", "e5f6g", "xyz", "123", "a3"]; const processArray = (arr) => { const convert = ["one", "two", "three", "four","five","six","seven", "eaight", "nine"] arr.sort((a,b)=> { console.log(a,b) if(a.toLo