October 12th, 2024
What's missing in this code?
canJump([1, 1, 0, 1, 0]); // false
canJump([1, 2, 0, 1, 0]); // true
canJump([2, 5, 0, 0, 4]); // true
canJump([3, 2, 2, 0, 4]); // true
canJump([2, 0, 0, 0, 4]); // false
canJump([1, 3, 1, 1, 0]); // false
function canJump(nums) {
let maxReachable = 0;
for (let i = 0; i < nums.length; i++) {
if (i > maxReachable) {
return false;
}
maxReachable = Math.max(
, i +
);
if (maxReachable
nums.length - 1) {
return true;
}
}
return false;
}
Type or select from these options