Last active
June 26, 2017 09:00
-
-
Save faiwer/7baf523526dab6ac4b302268e16bb526 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const kittens = []; | |
for(const cat of cats) | |
{ | |
if(cat.months < 7) | |
{ | |
kittens.push(cat.name); | |
if(kittens.length === limit) | |
break; | |
} | |
} | |
// versus | |
const FUNC_NAME = (limit, predicate, list, i = 0, newList = []) => { | |
const isDone = limit <= 0 || i >= list.length | |
const isMatch = isDone ? undefined : predicate(list[i]) | |
return isDone ? newList : | |
isMatch ? FUNC_NAME(limit - 1, predicate, list, i + 1, [...newList, list[i]]) | |
: FUNC_NAME(limit, predicate, list, i + 1, newList) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment