question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make Coding Challenge: "Return a Sorted Array Without Changing the Original Array" accept .slice() to pass tests.

See original GitHub issue

Feature Request: Add array.slice() as valid method to clone/copy array and as an alternative to [].concat(array)

Link to challenge: https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/functional-programming/return-a-sorted-array-without-changing-the-original-array/

I often use array.slice() to return an array copy, as this is what MDN recommends. When I was working on this challenge I could not get it to pass, even though my solution was returning the correct answer. The challenge ONLY accepts answers that use the format [].concat(arr). The wording in the challenge is clear, but experience from earlier challenges hava been lenient as long as you provide a valid solution.

Other reasons:

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
RandellDawsoncommented, Mar 21, 2019

The challenge ONLY accepts answers that use the format [].concat(arr). The wording in the challenge is clear, but experience from earlier challenges hava been lenient as long as you provide a valid solution.

You have to also view the test text as part of the instructions for the challenges. In this case, one of the the challenge test expects you to use the concat method. It even mentions the concat method in the Description section of the challenge. Always read the test text to make sure you understand what is being asked of you.

0reactions
RandellDawsoncommented, Apr 9, 2019

@TimAndreJacobsen and @icatat After thinking a bit more about your points, I agree this challenge could be updated to allow any valid method for copying the array (arr.slice(), [],concat(arr), [...arr], Array.from(arr)) and other possible ways not mentioned. While looking at the challenge tests, I also realized someone could still technically hard-code the final return value, so I created a PR #35801 to address your concerns and attempt to not allow hard coding of the final array returned.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Return a Sorted Array Without Changing the Original Array
In this functional programming tutorial we return a sorted array without changing the original array. This video constitutes one part of ...
Read more >
How to splice an array without mutating the original Array?
Here, mutation means the changing of the original array. ... Create the clone of the array using the spread operator or slice method....
Read more >
Return a Sorted Array Without Changing the Original ...
The globalArray variable should not change. —tests with log comaring both arrays indicate that the globalArray has not been mutated.
Read more >
Arrays and slices - Learn Go with tests - GitBook
Sum will take an array of numbers and return the total. ... not compile, you will have to change the first test to...
Read more >
Merge Sort
Our first test will check to see if we can correctly merge two arrays. No sorting will happen yet. Here's the code to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found