Last active
April 21, 2017 06:54
-
-
Save schan90/2f848c4b11dbe9b731ab4ef559d5571e to your computer and use it in GitHub Desktop.
Wee2 firstCharacter-makeString
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
| var userInput = prompt("Enter a String:"); | |
| var makeString = function(s) { | |
| var result = ""; | |
| if (s[0] !== ' ') { | |
| result += s[0]; | |
| } | |
| for (var i = 1; i < s.length; i += 1) { | |
| if (s[i - 1] === ' ' && s[i] !== ' ') { | |
| result += s[i]; | |
| } | |
| } | |
| return result; | |
| } | |
| console.log(makeString(userInput)); |
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
| var userInput = prompt("Enter a String:"); | |
| var makeString = function(s) { | |
| return s.split(' ').map(element => element[0] || '').join(''); | |
| } | |
| console.log(makeString(userInput));} |
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
| var userInput = prompt("Enter a String:"); | |
| var makeString = function(s) { | |
| var slicedArr = s.split(" "); | |
| var result = ""; | |
| for (var i = 0; i < slicedArr.length; i += 1) { | |
| result += slicedArr[i][0]; | |
| } | |
| return result; | |
| } | |
| console.log(makeString(userInput)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment