Advanced Array Sort

Published by Mubashir Hassan in

Create a function that takes in an array of numbers and returns an array with the items from the original array stored in subarrays. Items of the same value should be in the same subarray.

Examples

advancedSort([2, 1, 2, 1]) ➞ [[2, 2], [1, 1]]

advancedSort([5, 4, 5, 5, 4, 3]) ➞ [[5, 5, 5], [4, 4], [3]]

advancedSort([3,2,1,3,2,1]) ➞ [[3,3],[2,2],[1,1]]

Notes

The subarrays should be returned in the order of each element's first appearance in the given array.

Watch a quick demo on how Edabit works.