dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
1.7 KiB
1.7 KiB
id, title, challengeType, dashedName
| id | title | challengeType | dashedName |
|---|---|---|---|
| 6a2037a68a0bc2aef0006001 | Challenge 339: Array Chunks | 29 | challenge-339 |
--description--
Given an array and a chunk size, return the array split into sub-arrays of that size.
- The last chunk may be smaller if the array doesn't divide evenly.
--hints--
chunk_array([1, 2, 3, 4, 5, 6], 3) should return [[1, 2, 3], [4, 5, 6]].
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(chunk_array([1, 2, 3, 4, 5, 6], 3), [[1, 2, 3], [4, 5, 6]])`)
}})
chunk_array([1, "two", 3, "four", 5, "six", 7, "eight"], 2) should return [[1, "two"], [3, "four"], [5, "six"], [7, "eight"]].
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(chunk_array([1, "two", 3, "four", 5, "six", 7, "eight"], 2), [[1, "two"], [3, "four"], [5, "six"], [7, "eight"]])`)
}})
chunk_array([1, 2, 3, 4, 5], 3) should return [[1, 2, 3], [4, 5]].
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(chunk_array([1, 2, 3, 4, 5], 3), [[1, 2, 3], [4, 5]])`)
}})
chunk_array(["a", "b", "c", "d", "e"], 1) should return [["a"], ["b"], ["c"], ["d"], ["e"]].
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(chunk_array(["a", "b", "c", "d", "e"], 1), [["a"], ["b"], ["c"], ["d"], ["e"]])`)
}})
chunk_array([1, 2, 3], 5) should return [[1, 2, 3]].
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(chunk_array([1, 2, 3], 5), [[1, 2, 3]])`)
}})
--seed--
--seed-contents--
def chunk_array(arr, size):
return arr
--solutions--
def chunk_array(arr, size):
return [arr[i:i + size] for i in range(0, len(arr), size)]