/**
*
* Ashish Patel
* e: ashishsushilPatel@gmail.com
* w: https://ashish.me
*
*/
/*
Check if a string (first argument, str) ends with the given target string (second argument, target).
This challenge can be solved with the .endsWith() method, which was introduced in ES2015. But for the purpose of this challenge, we would like you to use one of the JavaScript substring methods instead.
Remember to use Read-Search-Ask if you get stuck. Write your own code.
Example
confirmEnding("Abstraction", "action") returns true;
confirmEnding("Open sesame", "pen") returns false;
*/
function confirmEnding(str, target) {
return str.substr(str.length-target.length) === target
}
test('confirm Ending', () => {
expect(confirmEnding('Abstraction', 'action')).toEqual(true)
expect(confirmEnding('Open sesame', 'pen')).toEqual(false)
});
Created 2019-12-11T02:47:21+05:30 · Edit