I am trying to convert some python code into JavaScript code.
I have a python list comprehension that take the paramente a as input. a is a string such as "bac".
asubstring = [a[i:i + j] for j in range(1, len(a) + 1) for i in range(len(a) - j + 1)]
The output is: ['b', 'a', 'c', 'ba', 'ac', 'bac']
I converted it into JavaScript by doing:
let j = 1
let i = 0
while(j < aTrimmed.length+1) {
while(i < aTrimmed.length - j + 1) {
aSubstring.push(aTrimmed.slice(i, i+j))
i++
}
j++
}
However, my output is: [ 'b', 'a', 'c' ]
I am not sure what I am missing in the two while loops.
i = 0in the inner loop. I would suggest writing this using nestedforloops, then it's harder to make that mistake.