Jump Game in TypeScript

function canJump(nums: number[]): boolean {
    // Initialize the farthest reachable index to be the first index
    let maxReachable: number = 0;

    // Iterate over the array
    for (let i = 0; i < nums.length; i++) {
        // If the current index is greater than the maximum reachable index, we cannot reach this point
        if (i > maxReachable) {
            return false;
        }

        // Update the maximum reachable index
        maxReachable = Math.max(maxReachable, i + nums[i]);

        // If the maximum reachable index is at or beyond the last index, return true
        if (maxReachable >= nums.length - 1) {
            return true;
        }
    }

    // If we finish iterating through the array without returning true, it means we cannot reach the end
    return false;
}

PrevNext