-
-
Save tbuchok/8484124 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.