This is great and allows us to do some slicker functional code:
function take(num, list) {
if (num <= 0 || !list || list === []) return [];
var [head, ...tail] = list;
return [head].concat(take(num - 1, tail));
}
It's not as elegant as haskell but it's still nicer than it would be without the new syntax.Once we have support for tail call optimization, things will get really interesting.