Comment

Comment by baron816

The question is to make a function that will group the values of a linked list by odds and then evens. So 1->2->3->4->5->6 becomes 1->3->5->2->4->6. The solution essentially comes down to creating filter and concat methods for the LL, so you get something like:

  function groupByOddEven(ll) {
    var odds = ll.filter(isOdd);
    var evens = ll.filter(isEven);

    return odds.concat(evens)
  }
If anyone were to ever get this far on their own and implement the LinkedList class correctly, I would have them make it so that they could make a higher order function that would receive any predicate function and then group by those values first, then its complement.
parent baron816 8 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton