Skip to content

Sort an array alphabetically using the sort Method - need to specify the array should be returned from the function #43417

Closed

Description

@amberream

Affected page

https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/functional-programming/sort-an-array-alphabetically-using-the-sort-method

Your code

function alphabeticalOrder(arr) {
  // Only change code below this line
  arr.sort((a,b) => a === b ? 0 : a < b ? -1 : 1);

  // Only change code above this line
}
alphabeticalOrder(["a", "d", "c", "a", "z", "g"]);

Expected behavior

The instructions on this page say, "Use the sort method in the alphabeticalOrder function to sort the elements of arr in alphabetical order." Since sort happens in place, I didn't realize I need to return the value to pass the challenge, I kept thinking there was something wrong with my code. Maybe just adding a line "return arr;" in the template code would make this more clear, or updating the instructions to specify the array needs to be returned. Would be good to mention that sorting happens in place too, I only knew because I happened to look at the Mozilla documentation.

Activity

  1. added
    scope: curriculum
    status: waiting triage
    on Sep 9, 2021
  2. majestic-owl448 commented on Sep 9, 2021

    @majestic-owl448
    Contributor

    the tests say "should return", I'm not sure how much this would need to be changed, but yes, it would be more user friendly to make it more clear that the function should return the expected result

    I don't know what would be the best way tho

  3. gikf commented on Sep 9, 2021

    @gikf
    Member

    The function should return the sorted array.

    Maybe something like this, added to the instructions?

  4. majestic-owl448 commented on Sep 9, 2021

    @majestic-owl448
    Contributor

    That would work, let's go with it!


    Thanks for opening this issue.

    This looks something that can be fixed by "first time" code contributors to this repository. Here are the files that you should be looking at to work on a fix:

    List of files:

    1. https://github.com/freeCodeCamp/freeCodeCamp/blob/main/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/sort-an-array-alphabetically-using-the-sort-method.md

    Please make sure you read our guidelines for contributing, we prioritize contributors following the instructions in our guides. Join us in our chat room or the forum if you need help contributing, our moderators will guide you through this.

    Sometimes we may get more than one pull requests. We typically accept the most quality contribution followed by the one that is made first.

    Happy contributing.

  5. added
    first timers only
    and removed
    status: waiting triage
    on Sep 9, 2021
  6. abhinav-raman commented on Sep 12, 2021

    @abhinav-raman

    Is this issue fixed? I am a first-timer and interested in contributing to this issue.

  7. majestic-owl448 commented on Sep 12, 2021

    @majestic-owl448
    Contributor

    @abhinav-raman there is already an open PR targeting this issue

  8. added a commit that references this issue on Oct 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    first timers onlyscope: curriculum

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions