Every story and comment from the Hacker News API, in a layout borrowed from 2001.
A comment on Array Iteration Interview Problem.
I only got it down to 2 cases
function add1(arr, val, n) { var m = 0, i; if(n > 0) { for(i = 0; i < arr.length && m < n; i++) { if(arr[i] === val) { arr[i]++; m++; } } } else { for(i = arr.length; i >= 0 && (m !== n || !n); i--) { if(arr[i] === val) { arr[i]++; m--; } } } console.log(arr); }
There are no comments on this comment yet.
I only got it down to 2 cases