Skip to content

Instantly share code, notes, and snippets.

Created January 17, 2017 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/6fd1a4de0110833f2d7a941ad9b5fb94 to your computer and use it in GitHub Desktop.
Save anonymous/6fd1a4de0110833f2d7a941ad9b5fb94 to your computer and use it in GitHub Desktop.
String Manipulation String Manipulation // source https://jsbin.com/ticegu
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="String Manipulation">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>String Manipulation</title>
</head>
<body>
<script id="jsbin-javascript">
/*
* 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
</script>
<script id="jsbin-source-javascript" type="text/javascript">/*
* 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
</script></body>
</html>
/*
* 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