|
|
|
|
|
by throwitaway1123
621 days ago
|
|
Yeah the comment I was originally responding to included a for loop (in the Pastebin link). My point is that if you're set on going down the functional route you don't need separate map and filter steps, you can just use flatMap which is effectively a filter and map combined (returning an empty array filters out the current value, since an empty array gets flattened into nothing). Of course, if you want the most performant solution an imperative for loop is faster (which is what I said in my last comment). |
|
or if you want it really silly.
input.reduce((a, b) => a + (b % 2 && b * 2), 0)
dont ask me why but for(a of b) is slower than for(i=0;i<b.length;i++)