Long Pressed Name LeetCode solution in JavaScript
1var isLongPressedName = function (name, typed) {2let i = 0;3let j = 0;4while (j < typed.length) {5if (i < name.length && name[i] === typed[j]) i++;6else if (typed[j] !== typed[j - 1]) return false; // this needs when name is traversed but there is tail of characters in typed7j++; // Base case. keep going through typed anyway hitting first condition from time to time: (i < name.length && name[i] === typed[j])8}910return i === name.length;11};