scrimba
Note at 0:03
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

AboutCommentsNotes
Note at 0:03
Expand for more info
main.js
run
preview
console
function sortByLength(strs) {
// write code here.
let a = strs.sort(function(a, b){return a.length - b.length});
return a
}



/**
* Test Suite
*/
describe('sortByLength()', () => {
it('sorts the strings from shortest to longest', () => {
// arrange
const strs = ["abc", "", "aaa", "a", "zz"];

// act
const result = sortByLength(strs);

// log
console.log("result: ", result);

// assert
expect(result).toEqual(["", "a", "zz", "abc", "aaa"]);
});
});
Console
"result: "
,
[
""
,
"a"
,
"zz"
,
"abc"
,
"aaa"
]
,
/index.html
LIVE