6 kyu

Organise duplicate numbers in list

1,017 of 2,296dangerdak

Description:

Sam is an avid collector of numbers. Every time he finds a new number he throws it on the top of his number-pile. Help Sam organise his collection so he can take it to the International Number Collectors Conference in Cologne.

Given an array of numbers, your function should return an array of arrays, where each subarray contains all the duplicates of a particular number. Subarrays should be in the same order as the first occurence of the number they contain:

group([3, 2, 6, 2, 1, 3])
>>> [[3, 3], [2, 2], [6], [1]]

Assume the input is always going to be an array of numbers. If the input is an empty array, an empty array should be returned.

Arrays
Sorting
Fundamentals

More By Author:

Check out these other kata created by dangerdak

Stats:

CreatedJan 22, 2017
PublishedFeb 22, 2017
Warriors Trained4135
Total Skips520
Total Code Submissions8267
Total Times Completed2296
JavaScript Completions1017
PHP Completions187
Python Completions945
Ruby Completions201
Crystal Completions11
Total Stars79
% of votes with a positive feedback rating95% of 512
Total "Very Satisfied" Votes465
Total "Somewhat Satisfied" Votes42
Total "Not Satisfied" Votes5
Total Rank Assessments13
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • dangerdak Avatar
  • GiacomoSorbi Avatar
  • HerrWert Avatar
  • mkasberg Avatar
  • Voile Avatar
  • ejini战神 Avatar
  • saudiGuy Avatar
Ad