Skip to content

Instantly share code, notes, and snippets.

View themonster2015's full-sized avatar
👋

Yen Vo themonster2015

👋
  • Spain
View GitHub Profile
@danyaljj
danyaljj / sort_map_js
Created July 16, 2015 23:03
Sort map by its keys and return another map in Javascript
sortMapByValue(map) {
var tupleArray = [];
for (var key in map) tupleArray.push([key, map[key]]);
tupleArray.sort(function (a, b) {
return b[1] - a[1]
});
var sortedMap = {};
tupleArray.forEach(function (el) {
sortedMap[el[0]] = el[1]
});