Retired
String chunks (retired)
457 of 1,020keune
Description:
You should write a function that takes a string and a positive integer n
, splits the string into parts of length n
and returns them in an array. It is ok for the last element to have less than n
characters.
If n
is not a number or not a valid size (> 0
) (or is absent), you should return an empty array.
If n
is greater than the length of the string, you should return an array with the only element being the same string.
Examples:
string_chunk('codewars', 2) # ['co', 'de', 'wa', 'rs']
string_chunk('thiskataeasy', 4) # ['this', 'kata', 'easy']
string_chunk('hello world', 3) # ['hel', 'lo ', 'wor', 'ld']
string_chunk('sunny day', 0) # []
Strings
Fundamentals
Similar Kata:
Stats:
Created | Jul 26, 2015 |
Warriors Trained | 1900 |
Total Skips | 174 |
Total Code Submissions | 11536 |
Total Times Completed | 1020 |
JavaScript Completions | 578 |
CoffeeScript Completions | 14 |
Python Completions | 457 |
Total Stars | 32 |
% of votes with a positive feedback rating | 82% of 223 |
Total "Very Satisfied" Votes | 165 |
Total "Somewhat Satisfied" Votes | 37 |
Total "Not Satisfied" Votes | 21 |