Created
April 23, 2019 17:15
-
-
Save juliarose/04a543ea62eb53013fe1354a972f5b44 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
/** | |
* Partition array based on conditions | |
* @param {Array} arr - Array | |
* @param {Function} fn - Function to satisfy | |
* @returns {Array} Partitioned array | |
*/ | |
function partition(arr, fn) { | |
let result = [[],[]]; | |
for (let i = 0; i < arr.length; i++) { | |
result[fn(arr[i]) ? 0 : 1].push(arr[i]); | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment