Is there a way to sort the following values: 1, 99, 1, 50 in javascript?
Given the input:
var map = {test:1, test2:99, test3:1, test4: 50}
The desired output is:
{test2:99, test4:50, test3:1, test:1}
This is the approach I have attempted:
function sortMap(map) {
var temp = [];
for(let prop in map) {
if(map.hasOwnProperty(prop)) {
temp.push({name:prop, size:map[prop]});
}
}
return temp.sort(function(b, a) {
return a.size - b.size
});
}