Draft

Sort a sentence by words' length

Description:

Write a function sortByLength() that takes an array of strings and returns a two-dimensional array.

Each sub-array must regroup words of the same length. Their order must be the same as they appear in the input string.

The sub-arrays must be sorted by words' length, ascending.

sortByLength(['The', 'quick', 'brown', 'fox', 'jumps', 'over', 'the', 'lazy', 'dog'])

must return

[
  [ 'The', 'fox', 'the', 'dog' ],
  [ 'over', 'lazy' ],
  [ 'quick', 'brown', 'jumps' ]
]

If the input is empty or not a string, return an empty array.

Strings will only contain words and spaces, so don't worry about punctuation.

Stats:

CreatedJan 12, 2022
Warriors Trained10
Total Skips0
Total Code Submissions17
Total Times Completed6
JavaScript Completions6
Total Stars0
% of votes with a positive feedback rating0% of 3
Total "Very Satisfied" Votes0
Total "Somewhat Satisfied" Votes0
Total "Not Satisfied" Votes3
Total Rank Assessments4
Average Assessed Rank
7 kyu
Highest Assessed Rank
7 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • VincentCMLejeune Avatar
Ad