I am new to JavaScript, and I found that there's a bug in my code as I type length as lenght . However, there is no notification for this bug or syntax error. It took me a long time to debug. I wonder how could this happens? If lenght is acceptable by JavaScript?
var totalFruit = function(tree) {
let windowStart = 0;
let dict = {};
maxLength = 0;
for (let windowEnd = 0; windowEnd < tree.length; windowEnd++) {
currentFruit = tree[windowEnd];
if (!(currentFruit in dict)) {
dict[currentFruit] = 0;
}
dict[currentFruit] += 1;
while (Object.keys(dict).lenght > 2) {
leftFruit = tree[windowStart];
dict[leftFruit] -= 1;
if (dict[leftFruit] == 0) {
delete dict[leftFruit]
windowStart += 1;
}
}
maxLength = Math.max(maxLength, windowEnd - windowStart + 1);
}
return maxLength;
};