Decompose the problem into two parts you can solve separately (or use existing tools to solve):
- Extract the second element of each sub-array--into a new, one-level array.
- Find the minimum of an array.
For the first, we use map to create a new array from an old one, by applying some transformation to each element. In this case, the transformation is to extract the second element, and convert it to a number, so:
Things.map(([,num]) => +num))
[,num] means to assign the second element of the array passed in to the parameter num), and the the plus sign makes sure it's a number. See below for the non-ES6 version.
For the second, we can just use Math.min.
Combining these, we can write:
Math.min(...Things.map(([,num]) => +num)))
Math.min(...) passes all the elements in the mapped array (the numbers) as parameters to Math.min.
Obligatory disclaimer: the => is the ES6 arrow function, the [,num] is ES6 parameter destructuring (, and ... is the ES6 parameter spread operator. These will work only in environments that support ES6 one way or another. Otherwise, fall back to
Math.min.apply(0, Things.map(function(elt) { return +elt[1]; }))
Arrayalready exists as the array class, and redefining it can have unforeseen consequences.Thingsis better (as it doesn't overwrite an existing JavaScript built-in), but still bad. Variables, by convention, are in camelcase in JavaScript (words stuck together, first being all lowercase, each consecutive word starting with a capital letter, like so:arrayOfThings). This is a point where all JS style guides agree on; here is Airbnb's.