Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
excellent
Use spoiler flag next time please.
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
Hi All,
about the filter callbacks, it is much more readable (a best practice) to use arrow function, and spare the closures, 'function', 'return' words.
Also why use filter, when we look for a position/index and there are array methods for that in JS.
Also return result (number.indexOf(...)) will perform a 3rd operation over the array. Not that the first 2 loops (filter) are necessary..
There should be better solutions in terms of best practices and cleverness IMO.
Sorry to spoil the pleasure of your findings
Could someone explain how this solution works? I was really scratching my head over this one.
Nice one mate, looks really clever.
Please check mine, on js banchmark is 86.25% faster. I think it could be even faster if I would compare first and last item in the array
"Mine tries to bail out as early as possible from the 1st loop itself."
...nope. 'return', in both .map() and .filter() just return from the current iteration; the loop still continues.
Use a for() loop and 'break' to exit early.
I guess since everyone is showing off their solution, I will too...
anyone like it? :)
No, your solution isn't "much more efficient". Only one iteration is needed. You still iterate two or three times.
this code falls sample tests iqTest("2 1 2")
Hmmm, so many answers with unnecessary extra loops.
Mine tries to bail out as early as possible from the 1st loop itself.
You don't even need to filter the whole array, just the first 3 numbers.
your solution must be top one
Ouch... This solution get top votes!
Loading more items...