Skip to content

Commit 8cc7f5a

Browse files
authored
Create 1636-sort-array-by-increasing-frequency.js
1 parent cb7951b commit 8cc7f5a

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @param {number[]} nums
3+
* @return {number[]}
4+
*/
5+
const frequencySort = function(nums) {
6+
const hash = {}
7+
for(let e of nums) {
8+
if(hash[e] == null) hash[e] = 0
9+
hash[e]++
10+
}
11+
nums.sort((a, b) => hash[a] === hash[b] ? b - a : hash[a] - hash[b])
12+
return nums
13+
};

0 commit comments

Comments
 (0)