JSFiddle - React, Tailwind, and code Playground

by Nidhi Patel

JavaScript

function canSpell(spell, sentence) {
  let i = 0;
  for (let j = 0; j < sentence.length; j++) {
    let c = sentence.charAt(j);
    if (c == spell.charAt(i)) {
      i++;
      if (i == spell.length) {
       return true;
       }
    }
  }
  return false;
}
console.log(canSpell("boom", "every breath you take every move you make"));
console.log(canSpell("boom", "i'm a cowboy on a steel horse i ride, i'm wanted"));
console.log(canSpell("boom", "moorbid"));