Skip to content

Instantly share code, notes, and snippets.

@tbuchok
Forked from robpe/coderbyte.js
Last active January 3, 2016 15:39
Show Gist options
  • Save tbuchok/8484124 to your computer and use it in GitHub Desktop.
Save tbuchok/8484124 to your computer and use it in GitHub Desktop.
function fn(array) {
return array
.sort(function(a,b) { return a - b })
.reduce(function(sum, val, idx, sorted) {
// this still has holes in it, not testing correct things:
return (idx == sorted.length - 1) ? sum > sorted[idx] : sum + val;
}, 0);
}
console.log('[4, 6, 23, 10, 1, 3]', fn([4, 6, 23, 10, 1, 3])); //=> true
console.log('[3, 5, -1, 8, 12]', fn([3, 5, -1, 8, 12])); //=> true
console.log('[1, 2, 3, 100]', fn([1, 2, 3, 100])); //=> false
@tbuchok
Copy link
Author

tbuchok commented Jan 18, 2014

realizing this has a lot of holes.

BUT was curious if we could do this with just Array.prototype functions ... maybe we can work together and figure something out for fun.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment