Created
March 14, 2014 14:18
-
-
Save br0xen/9548547 to your computer and use it in GitHub Desktop.
devict.org Code Challenge - Partition On
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 partitionOn(pred, items) { | |
var sp_idx = 0; | |
for(var i in items) { | |
if(!pred(items[i])) { | |
// If the predicate is false, move it to sp_idx, otherwise, leave it. | |
items.splice((sp_idx++), 0, items.splice(i, 1)[0]); | |
} | |
} | |
return sp_idx; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment