Skip to content

Instantly share code, notes, and snippets.

@cocodrino
Last active November 6, 2020 19:50
Show Gist options
  • Save cocodrino/b726a3c13fc603f859209e0b7de223ef to your computer and use it in GitHub Desktop.
Save cocodrino/b726a3c13fc603f859209e0b7de223ef to your computer and use it in GitHub Desktop.
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