← Back to challenges

N-Sized Parts

JavaScriptHardstringsarrays

Instructions

Create a function that divides a string into parts of size n.

Examples

partition("chew", 2) ➞ ["ch", "ew"]

partition("thematic", 4) ➞ ["them", "atic"]

partition("c++", 2) ➞ ["c+", "+"]

Notes

For inputs that do not split evenly into parts of size n, the last element in the array will have a "leftover" string (see example #3).

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: RegEx XXII : Unicode property escapes