JSFiddle - React, Tailwind, and code Playground
by nomadev
JavaScript
// Complete the hackerrankInString function below.
function hackerrankInString(s) {
const target = 'hackerrank'.split('');
const output = target.every(ch => {
const index = s.indexOf(ch);
if (index === -1)
return false;
else {
s = s.substr(index+1, s.length-1);
return true;
}
})
if (output) {
return 'YES';
} else {
return 'NO';
}
}
// hackerrank
console.log(hackerrankInString('hereiamstackerrank'));