@vaporeon_ it's even worse than you think! javascript has what is effectively a preprocessing phase where it looks for every single value initialized as a var and initializes them, and then the interpreter runs on the code like you would expect
this means you can use a variable before it is declared if you declare it with var! real javascript code out in the wild actually does this!!!!
@vaporeon_ @aescling no clue i just think the idea of storing project versions on laserdisc funny
@aescling @vaporeon_ with let the algo ran the test cases ~700ms and with var it shaved ~100ms
@aescling @vaporeon_ ....it runs faster with this change
@soft PREACH
@vaporeon_ oooooh I could have done for (var min = Infinity, j = 1, res; j <= nums[i]; ++j) res = 1 + jump(nums, i + j, gorp), min = res < min ? res : min;
javascript variables declared with var and not block scoped, so min is available outside of the for loop teehee
@aescling @vaporeon_ I just ran it and what is here is correct
@vaporeon_ here is another hack with a "beautiful" one liner:
Problem Statement
You are given a 0-indexed array of integers nums of length n. You are initially positioned at nums[0].
Each element nums[i] represents the maximum length of a forward jump from index i. In other words, if you are at nums[i], you can jump to any nums[i + j] where:
0 <= j <= nums[i] andi + j < nReturn the minimum number of jumps to reach nums[n - 1]. The test cases are generated such that you can reach nums[n - 1].
Example
[2,3,1,1,4]2The minimum number of jumps to reach the last index is 2. Jump 1 step from index 0 to 1, then 3 steps to the last index.Code
const jump = (nums, i = 0, gorp = {}) => {
if (i === nums.length - 1) return 0;
if (i > nums.length - 1 || nums[i] === 0) return Infinity;
if (gorp[i] !== undefined) return gorp[i];
let min = Infinity;
for (let j = 1, res; j <= nums[i]; ++j) res = 1 + jump(nums, i + j, gorp), min = res < min ? res : min;
return gorp[i] = min;
};
@coriander @wohali I was gonna write this comment too, lol
@onfy whoa new pfp
@vaporeon_ you store all versions of your software on laserdisc
secret do not open
@coriander break stuff
@coriander that phrase immediately filled with me with ick so im glad you think they are bad
@coriander they didn't sound good from the wikipedia description but i didn't say anything in case you liked them
@coriander my parents obsessively policed every kind of art I consumed until I was in my last year or two of high school so I have gaps in my knowledge media from the early 2000s that wasn't family entertainment
@coriander what genre are they
@kit yes im glad someone else understands
i go by Clodsire, Clodboy and Catwin.
videogame enjoyer. mathematics hobbyist and recovering physicist. software engineer. professional wonk. prophet of The Truth. the walking embodiment of "not diagnosed, but somethings wrong". i like animals that wear cowboy hats.
number of fat cock awards received: 56
header is by @vaporeon_
"i regret ever allowing him here" ~aescling
"oh you're one of those weird movie likers" ~Ti
"the thing you need to understand about @wallhackio is that he is utterly sick in the head. this is partially a compliment. but not entirely" ~aescling
30+
he/him