refactor: Add util.sorted_ids().

We borrowed this from typing_data.js and gave it a slightly
different name (sorted -> sorted_ids).
This commit is contained in:
Steve Howell
2018-04-25 20:55:32 +00:00
committed by Tim Abbott
parent a0e8a37e7f
commit 76b97d8b54
3 changed files with 20 additions and 15 deletions

View File

@@ -270,6 +270,22 @@ exports.emoji_prefix_sort = function (query, objs, get_item) {
return { matches: popular_emoji_matches.concat(other_emoji_matches), rest: prefix_sort.rest };
};
function to_int(s) {
return parseInt(s, 10);
}
exports.sorted_ids = function (ids) {
// This mapping makes sure we are using ints, and
// it also makes sure we don't mutate the list.
var id_list = _.map(ids, to_int);
id_list.sort(function (a, b) {
return a - b;
});
id_list = _.uniq(id_list, true);
return id_list;
};
return exports;
}());