Question: write JavaScript code to solve this algorithm: An array of integers arr, of size n is defined as [a[0], a[1], ..., a[n-1]. You will be
write JavaScript code to solve this algorithm:
An array of integers arr, of size n is defined as [a[0], a[1], ..., a[n-1]. You will be given an array of integers to sort. Sorting must first be by frequency of occurrence, then by value. For instance, given an array [4, 5, 6, 5, 4, 3], there is one each of 6's and 3's, and there are two 4's, two 5's. The sorted list is [3, 6, 4, 4, 5, 5].
Function Description Complete the function customSort in the editor below. The function must return an array sorted ascending first by frequency of occurrence, then by value within frequency.
customSort has the following parameter(s): arr[arr ,...arr ]: an array of integers to sort
Constraints 1 n 2 10 1 arr[i] 10
Sample Input 0 5 3 1 2 2 4 Sample Output 0 1 3 4 2 2
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
