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.
Me and my 60 lines of code ...
nice point to consider
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
This comment is hidden because it contains spoiler information about the solution
"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.
This comment is hidden because it contains spoiler information about the solution
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.
Loading more items...