Complete the code to sort the array of objects by age using a stable sort.
people.sort((a, b) => a.age [1] b.age);The subtraction operator - returns a negative, zero, or positive number which is required for the sort callback to work correctly and maintain stability.
Complete the code to keep the original order of items with the same score using a stable sort.
items.sort((a, b) => a.score [1] b.score);Subtracting b.score from a.score returns a number that the sort method uses to order items, preserving stability for equal scores.
Fix the error in the code to ensure stable sorting by name when ages are equal.
people.sort((a, b) => a.age - b.age || a.name [1] b.name);When ages are equal, comparing names with < returns a boolean which can be converted to a number to decide order. This helps keep the sort stable by name.
Fill both blanks to create a dictionary of word lengths for words longer than 3 characters.
{ [1]: [2] for word in words if word.length > 3 }The key is the word itself, and the value is its length using word.length in JavaScript.
Fill all three blanks to filter and map an array of numbers to their squares if they are even.
const result = numbers.filter(n => n [1] 2 === 0).map(n => n [2] [3]);
Use % to check even numbers, then n ** 2 to get the square.