Hacker News new | ask | show | jobs
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)
2 comments

I don't see where you used map? You made a recursive function? the argument was clearly stated - person says all most programmers need is map and reduce on arrays. I agree that by recursing you also have found another way not to use break but you have evidently had to NOT use map and reduce to do it?

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?

ok someone showed a way you can achieve break like functionality with map https://news.ycombinator.com/item?id=30306256 by mutating the array parameter of the map.