Skip to content

Instantly share code, notes, and snippets.

@misterussell
Created November 16, 2016 16:09
Show Gist options
  • Save misterussell/f04b72e5fb46ec13afde080d6316de14 to your computer and use it in GitHub Desktop.
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.
// 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