Created
May 30, 2019 10:14
-
-
Save ivanji/9ad10562e0de01a71fdffb0e4f3bd0fe to your computer and use it in GitHub Desktop.
// source https://jsbin.com
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width"> | |
| <title>JS Bin</title> | |
| </head> | |
| <body> | |
| <script id="jsbin-javascript"> | |
| function accum(s) { | |
| /* | |
| a place to store result | |
| iterate over s | |
| // append the current letter times i+1 to the result | |
| // capitalise first letter | |
| // append a dash if not last letter | |
| */ | |
| let result = ""; | |
| for (let i = 0; i < s.length; i++) { | |
| const counter = i +1; | |
| result += s[i].toLowerCase().repeat(counter) | |
| if (i !== s.length -1) { | |
| result += "-" | |
| } | |
| } | |
| return result.replace(/(^\w)|\-\w/g, function(c) { return c.toUpperCase(); }) | |
| } | |
| console.log(accum("hola")) | |
| </script> | |
| <script id="jsbin-source-javascript" type="text/javascript">function accum(s) { | |
| /* | |
| a place to store result | |
| iterate over s | |
| // append the current letter times i+1 to the result | |
| // capitalise first letter | |
| // append a dash if not last letter | |
| */ | |
| let result = ""; | |
| for (let i = 0; i < s.length; i++) { | |
| const counter = i +1; | |
| result += s[i].toLowerCase().repeat(counter) | |
| if (i !== s.length -1) { | |
| result += "-" | |
| } | |
| } | |
| return result.replace(/(^\w)|\-\w/g, function(c) { return c.toUpperCase(); }) | |
| } | |
| console.log(accum("hola"))</script></body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function accum(s) { | |
| /* | |
| a place to store result | |
| iterate over s | |
| // append the current letter times i+1 to the result | |
| // capitalise first letter | |
| // append a dash if not last letter | |
| */ | |
| let result = ""; | |
| for (let i = 0; i < s.length; i++) { | |
| const counter = i +1; | |
| result += s[i].toLowerCase().repeat(counter) | |
| if (i !== s.length -1) { | |
| result += "-" | |
| } | |
| } | |
| return result.replace(/(^\w)|\-\w/g, function(c) { return c.toUpperCase(); }) | |
| } | |
| console.log(accum("hola")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment