String Pairs

Published by Mubashir Hassan in

Create a function that takes a string str and returns an array of two-paired characters. If the string has an odd number of characters, add an asterisk * in the final pair.

See the below examples for a better understanding:

Examples

stringPairs("mubashir") ➞ ["mu", "ba", "sh", "ir"]

stringPairs("edabit") ➞ ["ed", "ab", "it"]

stringPairs("airforces") ➞ ["ai", "rf", "or", "ce", "s*"]

Notes

  • Return [] if the given string is empty.
Watch a quick demo on how Edabit works.