Split the String into N Cases of Equal Length

Published by Sinomede in

Create a function that accepts string input and int cases as parameters where the string is split into N distinct cases of equal length as shown:

Examples

SplitNCases("Strengthened", 6) ➞ { "St", "re", "ng", "th", "en", "ed" }

SplitNCases("Unscrupulous", 2) ➞ { "Unscru", "pulous" }

SplitNCases("Flavorless", 1) ➞ { "Flavorless" }

Notes

If it's not possible to split the string as described, return { "Error" }.

Watch a quick demo on how Edabit works.