// //interceptor // //npm package // //mfe // interface parent{ // name ?: string | Array<String> ; // } //rtk interface vs type // interface child extends parent{ // age: number; // } // function Button(onClick ,type='fill'){ // <button id="btn" onClick={onClick}>Click</button> // } var a = [1,2,[3,[4,[5],6]],7,8,[9]] //output:- [1,2,3,4,5,6,7,8,9] const flatArray =(arr,res=[])=>{ for(let el of arr){ if(Array.isArray(el)){ flatArray(el,res) } else{ res.push(el) } } return res; } const res= flatArray(a); console.log(res)
Posts
Axtria
- Get link
- X
- Other Apps
//contrcutor // render // // useMemo(()=>{ // const ab=function sum(){ // return a+b; // } // return sum // },[a,b]) // useCallback(()=>{ // return function(){ // } // },[]) // React.memo(<child />) //==> pure component //interseptor // var a=3; // var b=a++;//4 // var c=++a;//3 // console.log(a,b,c)//3,4,3 // const a = { x: 1, y: 2 }; // const b = a; // b.x = 3; // console.log(a); // console.log(b); const length = 4; const numbers = []; for (var i = 0; i < length; i++);{ numbers.push(i + 1); } //0+1 //1 //2 //3 [1,2,3,4]
Newgen
- Get link
- X
- Other Apps
/* find the max occurence of element in arr output =>{ 3:4 } */ const arr =[1,2,2,2,,4,5,3,3,3,3]; function maxOccurance(arr){ let hashMap={} let maxOccuranceKey=0; let ans={} for(let el of arr){ if(hashMap[el] !==undefined){ hashMap[el]+=1; maxOccuranceKey = Math.max(maxOccuranceKey,hashMap[el]) } else{ hashMap[el]=1; } } Object.entries(hashMap).forEach(([key,val])=>{ if(val===maxOccuranceKey){ ans[key]=val; } }) return ans; } const res= maxOccurance(arr); console.log(res) // const optimized=useCallback(()=>{ // },[])
Magic edtech
- Get link
- X
- Other Apps
https://codepen.io/ankittyagi206/pen/GRLbRNy // function outer(x){ // return function(y){ // return x*y; // } // } // console.log(outer(3)(4)) //map --> [] --> [] const obj={ name:'ankit' } const obj2= {...obj,...{ age:26 }} delete obj2.name console.log(obj2,obj) deep copy shallow copy promises async await // Given a string S containing alphanumeric characters, // The task is to calculate the sum of all numbers present in the string. // Output: 24 // Explanation: 1 + 23 = 24 // const input= '1abc22' // function calculateSum(input){ // let numArr =[]; // for(let i=0; i<input.length;i++){ // if(+input[i] && +input[i+1]){ // let newNum=Number([input[i],input[i+1]].join('')); // numArr.push(newNum) // } // else if(+input[...
Aristocrat --
- Get link
- X
- Other Apps
learn classes and oops concept in js // const arr=[1,2,3] // interface puppy{ // color:String // } // interface cat extends puppy{ // legs: Number // } //Sort this array of objects by key // var ob = [ // { "abc": 100 }, // { "mno": 200 }, // { "def": 100 }, // { "pqr": 500 } // ] // const res=ob.map((el)=>Object.keys(el)[0]); // let ans= res.sort().reduce((acc,curr)=>{ // acc[curr]= ob.find((el)=>Object.keys(el)[0]===curr)[`${curr}`] // return acc; // },{}) // console.log([ans]) const obj ={ name:'Ankit', printName:function( console.log(this.name) ) } const obj2 ={ name:'Ankidddt' } obj.printName.call(obj2) //call ,apply --> // printName.call(thisArg,'state','') // printName.apply(thisArg,['','']) //