Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Chapter 5] Inaccurate implementation of the slice function #32

Open
ahmadalfy opened this issue Sep 30, 2020 · 0 comments
Open

[Chapter 5] Inaccurate implementation of the slice function #32

ahmadalfy opened this issue Sep 30, 2020 · 0 comments

Comments

@ahmadalfy
Copy link

Earlier in chapter 5 about Arrays, it was mentioned that passing no argument to the slice function returns a copy of the array. So if we tried to do:

var array = [1, 2, 3];
console.log(array.slice() === array); // this will return false

While in your example here you are returning the array itself so:

var array = [1, 2, 3];
console.log(arraySlice(array) === array); // this will return true

I think it should be replaced by:

    if (!beginIndex && !endIndex) {
        return Array.from(array);
    }
@ahmadalfy ahmadalfy changed the title Inaccurate implementation of the slice function in Arrays [Chapter 5] Inaccurate implementation of the slice function Sep 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant