There is a recursive function called `longestToShortest` which takes an array of lowercase ot strings and returns them sorted from longest to shortest. Strings of equal length should be sorted alphabetically. Your function should accept a default argument called `sorted` which holds the currently sorted elements. Each recursive step should add the shortest string in the `strings` array to the end of `sorted`. // Examples: // Sorts strings from shortest to longest let strings1 = ["abc", "de", "", "f", "ghijk", "lmno"] shortestToLongest(strings1); // ['', 'f', 'de', 'abc', 'lmno', 'ghijk'] function longestToShortest(strings, sorted = []) { } Please explain all steps Line by line, Show all work inside the function to pass the example console.log test cases. Please do it in the recursive function only. Thank you!
There is a recursive function called `longestToShortest` which takes
an array of lowercase ot strings and returns them sorted from longest
to shortest. Strings of equal length should be sorted alphabetically. Your function should accept a default argument called `sorted` which holds the currently sorted elements. Each recursive step should add
the shortest string in the `strings` array to the end of `sorted`. // Examples:
// Sorts strings from shortest to longest
let strings1 = ["abc", "de", "", "f", "ghijk", "lmno"]
shortestToLongest(strings1);
// ['', 'f', 'de', 'abc', 'lmno', 'ghijk']
function longestToShortest(strings, sorted = []) {
}
Please explain all steps Line by line, Show all work inside the function to pass the example console.log test cases. Please do it in the recursive function only. Thank you!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images