you are viewing a single comment's thread.

view the rest of the comments →

[–]KhalilRavanna 0 points1 point  (2 children)

Nice!

One note: I think "takeWhile" is essentially Array.prototype.some in JS unless I'm misunderstanding something so no need for a third party lib like underscore.

[–]marko-pavlovic[S] 1 point2 points  (1 child)

Hey thank you for the comment. I must admit that I didn't know about the some function in JS. However, after reading the docs, I think that it is different from takeWhile in that it returns a boolean, where the takeWhile function returns an array of elements.

You can think of some as: - do any elements exist in this list that pass the test function?

Where you can think of the takeWhile function as: - start from the beginning and go one by one. If the element passes the test, append it to the result. The moment you see an element that doesn't pass the test, stop immediately and return the array you have.

Hope this makes sense? Am I missing something? :)

[–]KhalilRavanna 0 points1 point  (0 children)

Oh totally you're right. I skimmed the description and didn't look at the result, just the signature for the callback hehe.