AbdulMuttaqin

tes mumbling

Jan 15th, 2021 (edited)
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function mumbling(str) {
  2.   const helper = (str, index, result) => {
  3.     if (str.length === 1) {
  4.       const [char] = str
  5.       return result + char.toUpperCase() + char.toLowerCase().repeat(index - 1)
  6.     } else {
  7.       const [char, ...rest] = str
  8.       return helper(
  9.         rest,
  10.         index + 1,
  11.         result + char.toUpperCase() + char.toLowerCase().repeat(index - 1) + '-'
  12.       )
  13.     }
  14.   }
  15.  
  16.   return helper(str, 1, '')
  17. }
Add Comment
Please, Sign In to add comment