Simply we can like this. const flattenArray = []; const toFlatten = (params) =>{ for (let num of params) { if(Array.isArray(num)) { toFlatten(num) } else flattenArray.push(num); } } toFlatten(numArray);// Pass the array
Hi Buddy can you check the code once, const flattenArray = []; const toFlatten = (params) =>{ for (let num of params) { console.log(num) if(Array.isArray(num)) { toFlatten(num) } else flattenArray.push(num); } } console.log(toFlatten([1,2,[3,4,[5]]]))
@@uidevguide Bro, toFlatten function is not returning any thing here. we don't have the return statement. just try to console.log(flattenArray). You will get expected output. But if function need to return just add return flattenArray statement after loop. const flattenArray = []; const toFlatten = (params) =>{ for (let num of params) { if(Array.isArray(num)) { toFlatten(num) } else flattenArray.push(num); } return flattenArray } console.log('Print missing items', toFlatten([1,2,[3,4,[5]]])); May be you can have different approaches, it was just idea how we can achieve
Get the early access to zero to hero cheat sheet for you next interview ✅✅
topmate.io/ui_dev_guide/951823
what is the 35th question
why in the interview method chaining is said as currying
Bhai kabhi kabhi galti ho jati hai 😃
For an angular developer, should he know about JavaScript as well ?
Yes Vignesh.
You have know about it
Simply we can like this.
const flattenArray = [];
const toFlatten = (params) =>{
for (let num of params) {
if(Array.isArray(num)) {
toFlatten(num)
} else flattenArray.push(num);
}
}
toFlatten(numArray);// Pass the array
Hi Buddy can you check the code once,
const flattenArray = [];
const toFlatten = (params) =>{
for (let num of params) {
console.log(num)
if(Array.isArray(num)) {
toFlatten(num)
} else flattenArray.push(num);
}
}
console.log(toFlatten([1,2,[3,4,[5]]]))
@@uidevguide Bro, toFlatten function is not returning any thing here. we don't have the return statement. just try to console.log(flattenArray). You will get expected output. But if function need to return just add return flattenArray statement after loop.
const flattenArray = [];
const toFlatten = (params) =>{
for (let num of params) {
if(Array.isArray(num)) {
toFlatten(num)
} else flattenArray.push(num);
}
return flattenArray
}
console.log('Print missing items', toFlatten([1,2,[3,4,[5]]]));
May be you can have different approaches, it was just idea how we can achieve
Can you provide thease questions it well so it will be better
I think you should do it
Homework for you 😎
@@uidevguide sure will do
😂😂😂😂@@uidevguide
is he 10+ years exp?
He is 8 years of experience