Last Call

The following code from The Iron Yard baffled me for a little while. After having some help walking through it, it now makes sense.

The last print to screen there is just something I was messing around with to help me explain whats going on here.

The purpose of the assessment was to call the last number in an Array, without knowing the length. The bit of code within the brackets [long.length — 1] simply calls the length. long refers to the array. “.length” refers to the quantity of items in the array. The “-1” allows the previously discussed to get the exact quantity out of the array considering the first item in the array is referenced as zero.

All the above is then assigned, as an array index, to “long” (or “short”). Doing this, calls the last value, as if we knew the length already as in line 16.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.