Learn Intermediate Algorithmic Thinking by Building a Dice Game - Step 79

Tell us what’s happening:

Learn Intermediate Algorithmic Thinking by Building a Dice Game Step 79

I’m having trouble with this step. Any advice? Below is my current code:

arr.sort = (a, b) => a -b;
const sortedNumbersArr = arr;

Your code so far

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

/* file: styles.css */

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

const checkForStraights = (arr) => {
  arr.sort = (a, b) => a - b;
  const sortedNumbersArr = arr
};


// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36

Challenge Information:

Learn Intermediate Algorithmic Thinking by Building a Dice Game - Step 79

Hello @whoishieu!

Step 79

To check for a small or large straight, you will need to first sort the list of numbers in the array.

Use the sort method on the arr parameter and pass in a callback function. For the callback function, use a and b for the parameters and implicitly return a - b.

Assign that entire result to a const variable called sortedNumbersArr.

This is a very tricky step, particularly for the callback function part possibly.

Your code is very close to what is required, but contains some syntactic & logic errors.

It might be an idea to start by creating the sortedNumbersArr constant first, and then assign the sort operation to that constant.

Check out these articles: JavaScript Array Sort – How to Use JS Sort Methods (With Code Examples) & Array.prototype.sort()

Does this help?

Keep up the good progress!

Happy Coding! :slightly_smiling_face: