Skip to content

Instantly share code, notes, and snippets.

@risingBirdSong
Created December 29, 2019 04:16
Show Gist options
  • Select an option

  • Save risingBirdSong/2b02a40aed2cbf585a9e6877809eca6f to your computer and use it in GitHub Desktop.

Select an option

Save risingBirdSong/2b02a40aed2cbf585a9e6877809eca6f to your computer and use it in GitHub Desktop.
function accum(s:string){
return s.split('').map((letter, idx)=>{
let output = letter.repeat(idx + 1).toLowerCase();
return capitalizeFirstLetter(output);
}).join('-')
}
function capitalizeFirstLetter(string : string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
// and my favorite solution from another warrior
function accumtwo(s : string) {
return s.split('').map((c, i) => (c.toUpperCase() + c.toLowerCase().repeat(i))).join('-');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment