Code fails, don't know reason, also don't know fix
13:25 12 Jan 2026

Leetcode problem 10. Regular Expression Matching

Given an input string s and a pattern p, implement regular expression matching with support for '.' and '*' where:

  • '.' Matches any single character.​​​​

  • '*' Matches zero or more of the preceding element.

The matching should cover the entire input string (not partial).

/**
 * @param {string} s
 * @param {string} p
 * @return {boolean}
 */
var isMatch = function(s, p) {
    // Individualise the letters
    let sArr = [...s]
    let pArr = [...p]
    let backUpNum = 0;
    let backUpNum2 = 0;
    // main loop
    for(let i = 0; i

Code fails at:
s = "aab"

p = "c*a*b"

outputs false, the correct answer is true, I realise why it outputs false, but why should it be true and how?

javascript arrays recursion dynamic-programming