Sorts given array lexicographically.
Algorithms knows how to treat
differently length strings.
Algorithm is stable. Time complexity: O(N*M) for N keys which have M or fewer digits.
Algorithm is stable. Time complexity: O(N*M) for N keys which have M or fewer digits.
Parameters:
| Name | Type | Description |
|---|---|---|
arr |
Array | Array which should be sorted. |
d |
Number | Optional. Digit from which sorting should start. |
- Source:
Returns:
Sorted array.
- Type
- Array
Example
var sort = require('../src/sorting/msd').msd;
// [ 'aab', 'aaa', 'acc', 'bbb', 'bcc' ]
console.log(sort(['aab', 'bbb', 'aaa', 'acc', 'bcc']));