Message from JavaScript discussions

August 2020

— Eggheaddidation

— 

But really, i am looking forward to see what happens in the future, because microsoft tends to get closer and closer to chromium core, forking it and creating their own browser, commiting some features into original chromium core and they build blazor as runtime, not as built wasm module, the virtual dom is structured in way you could implement it natively into browser

— It either dies or we’ve got some possibility of seeing .net runtime in future browser cores lol

— Eggheaddidation is thinking that there is some chance that things like YEW will take over lol

— On the topic of edge, does anyone here play edge://surf (admittedly it's a completely unrelated question)

Message permanent page

— Lol

— Btw i think i recon who is destined to become a popular tech blogger🤔

— Hi Everyone,

i'm new to JS.

So,I stared solving a code challenge and this is the requirement.

Given an array of different type of elements as below.

[
"cat",
2,
0,
null,
["-1", undefined, {}, 7, ["car", "dog", 5, [2, 19], 2]],
];

I should return an array of only numbers.



I solved the code but when I used .push instead of .contact inside the reduce array method I got an error saying push isn't a function.


Can anyone please explain about the error and why shouldn't I use .push instead of .concat in this case.

Message permanent page

— Code :


const arr = [
"cat",
2,
0,
null,
["-1", undefined, {}, 7, ["car", "dog", 5, [2, 19], 2]],
];

const flatten = (array) => {
return array.reduce((result, item) => {
return result.concat(Array.isArray(item) ? flatten(item) : item);
}, []);
};
console.log(flatten(arr).filter((item) => typeof item === "number"));

Message permanent page

— Push is stateful, concat is stateless.
Which means push mutates the original array, whereas reduce expects to use the return value for the next iteration.

Message permanent page

— So concat is better in this case

— Can u explain in more detail ?