Created
November 16, 2016 16:09
-
-
Save misterussell/f04b72e5fb46ec13afde080d6316de14 to your computer and use it in GitHub Desktop.
A function that confirms the end of a string from a specified parameter.
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
// function to confirm the ending of a string | |
function confirmEnding(s, eS) { | |
// look at the end string (s) | |
// look at the end of the end string (eS) | |
// compare the index of the last of both | |
// cycle over the two string simulteanously | |
// if gets to the beginning of endString and nothing has been false | |
// return true | |
let splitString = s.split(''); | |
let splitEnd = eS.split(''); | |
let test = true; | |
console.log(splitString, splitEnd); | |
let i = 1; | |
do { | |
if (splitString[splitString.length - i] !== splitEnd[splitEnd.length - i]) { | |
test = false; | |
} | |
i++; | |
} while (i < splitEnd.length); | |
return test; | |
} | |
console.log(confirmEnding('this is awesome!', '!')); // true | |
console.log(confirmEnding('yape', 'eee')); // false | |
console.log(confirmEnding('mazing', 'zing')); // true | |
console.log(confirmEnding('zingboozing', 'zing')); // true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment