curriculum/challenges/english/blocks/rosetta-code-challenges/5a23c84252665b21eecc8016.md
Write a function to sort an array (or list) of strings in order of descending length, and in ascending lexicographic order for strings of equal length.
lengthSorter should be a function.
assert(typeof lengthSorter == 'function');
lengthSorter(["Here", "are", "some", "sample", "strings", "to", "be", "sorted"]) should return an array.
assert(
Array.isArray(
lengthSorter([
'Here',
'are',
'some',
'sample',
'strings',
'to',
'be',
'sorted'
])
)
);
lengthSorter(["Here", "are", "some", "sample", "strings", "to", "be", "sorted"]) should return ["strings", "sample", "sorted", "Here", "some", "are", "be", "to"].
assert.deepEqual(
lengthSorter([
'Here',
'are',
'some',
'sample',
'strings',
'to',
'be',
'sorted'
]),
['strings', 'sample', 'sorted', 'Here', 'some', 'are', 'be', 'to']
);
lengthSorter(["I", "hope", "your", "day", "is", "going", "good", "?"]) should return ["going", "good", "hope", "your", "day", "is", "?","I"].
assert.deepEqual(
lengthSorter(['I', 'hope', 'your', 'day', 'is', 'going', 'good', '?']),
['going', 'good', 'hope', 'your', 'day', 'is', '?', 'I']
);
lengthSorter(["Mine", "is", "going", "great"]) should return ["going", "great", "Mine", "is"].
assert.deepEqual(lengthSorter(['Mine', 'is', 'going', 'great']), [
'going',
'great',
'Mine',
'is'
]);
lengthSorter(["Have", "fun", "sorting", "!!"]) should return ["sorting", "Have", "fun", "!!"].
assert.deepEqual(lengthSorter(['Have', 'fun', 'sorting', '!!']), [
'sorting',
'Have',
'fun',
'!!'
]);
lengthSorter(["Everything", "is", "good", "!!"]) should return ["Everything", "good", "!!", "is"].
assert.deepEqual(lengthSorter(['Everything', 'is', 'good', '!!']), [
'Everything',
'good',
'!!',
'is'
]);
function lengthSorter(arr) {
}
function lengthSorter(arr) {
arr.sort(function(a, b) {
var result = b.length - a.length;
if (result == 0) result = a.localeCompare(b);
return result;
});
return arr;
}