Last active
November 6, 2020 19:50
-
-
Save cocodrino/b726a3c13fc603f859209e0b7de223ef to your computer and use it in GitHub Desktop.
javascript partition similar to clojure partition
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 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