Long Pressed Name LeetCode solution in JavaScript

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

10
return i === name.length;
11
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0