find the range of all keys in a map in typescript

To find the range of all keys in a TypeScript Map, we can use the spread operator with the Math.min and Math.max functions. Here's an example:

index.ts
const myMap = new Map<string, number>();
myMap.set('a', 1);
myMap.set('b', 2);
myMap.set('c', 3);

const allKeys = [...myMap.keys()];
const minKey = Math.min(...allKeys);
const maxKey = Math.max(...allKeys);

console.log(`Range of keys: ${minKey} to ${maxKey}`);
263 chars
11 lines

In this example, we first create a new Map with string keys and number values. We then use the spread operator to get an array of all the keys in the map. Finally, we use the Math.min and Math.max functions with the spread operator to find the minimum and maximum keys in the array, giving us the range of all keys in the map.

gistlibby LogSnag