0
0
DSA Javascriptprogramming~10 mins

Sorting Stability and When to Use Which Sort in DSA Javascript - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to sort the array of objects by age using a stable sort.

DSA Javascript
people.sort((a, b) => a.age [1] b.age);
Drag options to blanks, or click blank then click option'
A-
B+
C===
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using comparison operators like '>' or '===' which do not return the expected numeric value for sort.
2fill in blank
medium

Complete the code to keep the original order of items with the same score using a stable sort.

DSA Javascript
items.sort((a, b) => a.score [1] b.score);
Drag options to blanks, or click blank then click option'
A-
B===
C<
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using comparison operators that return boolean values instead of numbers.
3fill in blank
hard

Fix the error in the code to ensure stable sorting by name when ages are equal.

DSA Javascript
people.sort((a, b) => a.age - b.age || a.name [1] b.name);
Drag options to blanks, or click blank then click option'
A===
B>
C-
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction on strings which causes NaN and breaks sorting.
4fill in blank
hard

Fill both blanks to create a dictionary of word lengths for words longer than 3 characters.

DSA Javascript
{ [1]: [2] for word in words if word.length > 3 }
Drag options to blanks, or click blank then click option'
Aword
Blen(word)
Cword.length
Dword.upper()
Attempts:
3 left
💡 Hint
Common Mistakes
Using Python's len() function instead of JavaScript's length property.
5fill in blank
hard

Fill all three blanks to filter and map an array of numbers to their squares if they are even.

DSA Javascript
const result = numbers.filter(n => n [1] 2 === 0).map(n => n [2] [3]);
Drag options to blanks, or click blank then click option'
A%
B**
C2
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect operators for checking even numbers or squaring.