Skip to content

Instantly share code, notes, and snippets.

@TRobWE
Forked from anonymous/index.html
Created January 17, 2017 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TRobWE/06a25dced9ba859dc9ef830444841294 to your computer and use it in GitHub Desktop.
Save TRobWE/06a25dced9ba859dc9ef830444841294 to your computer and use it in GitHub Desktop.
String ManipulationString Manipulation// source https://jsbin.com/ticegu
/*
* 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