Last active
October 16, 2017 13:45
-
-
Save sofakingworld/03fc66c84d4cda1f70840b803b7d4b8b to your computer and use it in GitHub Desktop.
JavaScript analog of EachSlice from Ruby
This file contains hidden or 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
Array.prototype.eachSlice = function(size=1) { | |
return Array(Math.ceil(this.length / size)) | |
.fill() | |
.map(( _, idx) => { | |
return this.slice(idx * size, (1 + idx) * size) | |
}) | |
} |
Author
sofakingworld
commented
Oct 15, 2017
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment