To find the range of all values in a Map, you can convert the values of the Map into an array using the Array.from()
method and then use the Math.max()
and Math.min()
methods to find the maximum and minimum values in the array, respectively. Once you have found the maximum and minimum values, you can calculate the range by subtracting the minimum value from the maximum value.
Here's an example implementation in TypeScript:
index.ts273 chars11 lines
In this example, myMap
is a Map with string keys and number values. We first convert the values of the Map into an array using Array.from()
. We then use the spread operator (...
) to spread the values of the array into the Math.max()
and Math.min()
methods to find the maximum and minimum values, respectively. Finally, we calculate the range by subtracting the minimum value from the maximum value and log the result to the console.
gistlibby LogSnag