Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e30c7d5

Browse files
author
Coding Money
committed
array-chunking
1 parent f5a160a commit e30c7d5

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

‎completed_exercises/4-array-chunking.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,15 @@
88
// chunk([1, 2, 3, 4, 5], 4) --> [[ 1, 2, 3, 4], [5]]
99
// chunk([1, 2, 3, 4, 5], 10) --> [[ 1, 2, 3, 4, 5]]
1010

11-
function chunk(array, size) {}
11+
function chunk(array, size) {
12+
const result = []
13+
let index = 0
14+
while(index<array.length){
15+
result.push(array.slice(index,index+size))
16+
index += size
17+
}
18+
return result;
19+
}
20+
21+
console.log(chunk([1, 2, 3, 4, 5, 6, 7, 8], 3));
22+
// 0, 1, 2, 3, 4

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /