将列表理解python转换为javascript

我正在尝试将一些python代码转换为JavaScript代码。

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']

我通过执行以下操作将其转换为JavaScript:

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' ]

我不确定两个while循环中缺少什么。

评论