Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Sort with a sorting array

7 kyu link to kata
my solution

Sort an array according to the indices in another array.
It is guaranteed that the two arrays have the same size, and that the sorting array has all the required indices.

    sort(['x', 'y', 'z'], [1, 2, 0]) => ['z', 'x', 'y']
<span class="cm-variable">sort</span>([<span class="cm-string">'z'</span>, <span class="cm-string">'x'</span>, <span class="cm-string">'y'</span>], [<span class="cm-number">0</span>, <span class="cm-number">2</span>, <span class="cm-number">1</span>]) <span class="cm-operator">=&gt;</span> [<span class="cm-string">'z'</span>, <span class="cm-string">'y'</span>, <span class="cm-string">'x'</span>]