6 kyu
2 Arrays 1 Sort
143 of 297IVBakker
Description:
Imagine two arrays/lists where elements are linked by their positions in the array. For example:
HowMany = [ 1 , 6 , 5 , 0 ];
Type = ['house', 'car','pen','jeans'];
Means I have 1 house, 6 cars,5 pens and 0 jeans.
Now if we sort one array we lose the connectivity. The goal is to create a sorting function that keeps the position link linkedSort(arrayToSort,linkedArray,compareFunction)
. So for every element that moves in arrayToSort
(HowMany in the example), the corresponding element in linkedArray
(Type in the example) needs to move similarly.
For example in Javascript:
//INPUT
HowMany = [ 1 , 6 , 5 , 0 ];
Type = ['house', 'car','pen','jeans'];
//SORT
res = linkedSort(HowMany,Type,function(a,b){return a-b;})
//OUTPUT
HowMany === res === [ 0 , 1 , 5 , 6 ];
Type === ['jeans','house','pen','car'];
linkedSort(...)
return the "arrayToSort" sorted only.
If no compare function is provided you should handle like an alphabetical sorting would do, e.g:
yoursortingfunction([-71,-6,35,0]) === [-6,-71,0,35] != [-71,-6,0,35]
Note: it is assumed that array are same length.
Arrays
Algorithms
Sorting
Similar Kata:
Stats:
Created | Nov 18, 2014 |
Published | Nov 18, 2014 |
Warriors Trained | 1255 |
Total Skips | 42 |
Total Code Submissions | 2694 |
Total Times Completed | 297 |
JavaScript Completions | 151 |
Ruby Completions | 24 |
Python Completions | 143 |
Total Stars | 40 |
% of votes with a positive feedback rating | 80% of 131 |
Total "Very Satisfied" Votes | 92 |
Total "Somewhat Satisfied" Votes | 26 |
Total "Not Satisfied" Votes | 13 |
Total Rank Assessments | 27 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 4 kyu |
Lowest Assessed Rank | 7 kyu |