|
|
|
|
|
by xigoi
1585 days ago
|
|
const findInterestingItems = (arr, isInteresting, num, i=0) =>
num == 0 || i >= arr.length
? []
: isInteresting(arr[i])
? [arr[i], ...findInterestingItems(arr, isInteresting, num-1, i+1)]
: findInterestingItems(arr, isInteresting, num, i+1)
|
|
on edit: also how will that recursion perform on the large array we've supposed as being used if it turns out that we don't get our interesting items in early parts of array?