Learn Basic Algorithmic Thinking by Building a Number Sorter - Step 44

Tell us what’s happening:

My code does not pass. I’m not sure what I’m doing wrong. It says “Your callback function should use an explicit return.” But I am using an explicit return (I think).

Your code so far

<!-- file: index.html -->

/* file: styles.css */

/* file: script.js */
// User Editable Region

  const sortedValues = inputValues.sort((a, b) => {
if (a - b < 0) {
      return a - b}
  });

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.5 Safari/605.1.15

Challenge Information:

Learn Basic Algorithmic Thinking by Building a Number Sorter - Step 44

You are using explicit return. The problem is with the logic of the callback function.

The callback function should return a number where:

  • A negative value indicates that a should come before b.
  • A positive value indicates that a should come after b.
  • Zero or NaN indicates that a and b are considered equal.

Because of if (a - b < 0), you are only returning a value when elements a and b are already in the correct order.

1 Like