Skip to content

Instantly share code, notes, and snippets.

@cocodrino
Last active Nov 6, 2020
Embed
What would you like to do?
javascript partition similar to clojure partition
function partition(input, step,pad){
const output = [];
for (let i = 0; i < input.length; i += pad){
const part = input.slice(i, i + step)
if(part.length >=step )
output[output.length] = part
}
return output;
}
//> partition([2,3,4,5,6],2,1)
//[ [ 2, 3 ], [ 3, 4 ], [ 4, 5 ], [ 5, 6 ] ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment