-
-
Save TRobWE/06a25dced9ba859dc9ef830444841294 to your computer and use it in GitHub Desktop.
String ManipulationString Manipulation// source https://jsbin.com/ticegu
This file contains 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
/* | |
* STRING MANIPULATION: | |
* | |
* 0. There is a number of ways to manipulate strings in Javascript! To help | |
* show you a few I'll be showing examples of functions I've made that showcase | |
* string manipulation. One thing to note is that strings can be treated like an | |
* for the purpose bracket notation and using the property .length. | |
* Concatenation is another useful way to manipulate strings. | |
* By using the addition operator you can combine/concatenate strings. | |
*/ | |
function toDashCase(string) { | |
return string.replace(/[" "]/g,"-"); | |
//For the scope of this function globally replace all spaces with a Dash. Ta-Da! toDashCase! | |
} | |
console.log(toDashCase("Hello World!")); //prints "Hello-World!" | |
function concat(stringOne, stringTwo) { | |
return stringOne + stringTwo; | |
//Concatenation at its finest! | |
} | |
console.log(concat("It is a", " new day!")); //prints "It is a new day!" | |
function beginsWith(string, char) { | |
var pullIt = string.toLowerCase(); | |
if(pullIt[0] === char.toLowerCase()) { | |
return true; | |
} else { | |
return false; | |
} | |
//return true if the word starts with the same letter as the given character. | |
} | |
console.log(beginsWith("Now", "n")); //prints true | |
function endsWith(string, char) { | |
// YOUR CODE BELOW HERE // | |
if (string[string.length - 1].toLowerCase() === char.toLowerCase()) { | |
return true; | |
} else { | |
return false; | |
} | |
//return true if the word ends with the same letter as the given character. | |
} | |
console.log(endsWith("Now", "w")); //prints true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment