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

Fix splice mistake in day1 #362

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

asungy
Copy link

@asungy asungy commented Aug 4, 2023

Summary

This PR addresses a minor mistake made in the "Splice method in array" section in Day 1, as well as restructures some code for clarity.

Mistake with removing all elements using splice

Originally, the Day 1 tutorial claimed that the following code would remove all items:

const numbers = [1, 2, 3, 4, 5]
console.log(numbers.splice())

While numbers.splice() does return an empty list, it does not remove any items from numbers.

This can be seen in this demo.

Printing contents of numbers

As a corollary, it would be more informative to print the actual contents of numbers rather than the return values of the methods called on numbers, especially because splice modifies the array in-place.

// print return value of splice
console.log(numbers.splice(0, 1));

// print actual contents of spliced array
numbers.splice(0, 1);
console.log(numbers);

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

Successfully merging this pull request may close these issues.

None yet

1 participant