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

Day 5 method string.splice() #811

Open
NaraRaa opened this issue Jul 7, 2023 · 1 comment
Open

Day 5 method string.splice() #811

NaraRaa opened this issue Jul 7, 2023 · 1 comment

Comments

@NaraRaa
Copy link

NaraRaa commented Jul 7, 2023

  const numbers = [1, 2, 3, 4, 5, 6]
	numbers.splice(3, 3, 7, 8, 9)
  console.log(numbers.splice(3, 3, 7, 8, 9))  // -> [1, 2, 3, 7, 8, 9] //it removes three item and replace three items

small mistake - in case anyone who copy-pasted the code, got [7, 8, 9] instead of [1, 2, 3, 7, 8, 9] and started questioning life,
this is because the author called the splice() method twice, and splice() would modify the original array.

Corrected version:

  const numbers = [1, 2, 3, 4, 5, 6]
  console.log(numbers.splice(3, 3, 7, 8, 9)) // [4, 5, 6] - returns the removed items
  console.log(numbers) // [1, 2, 3, 7, 8, 9] - returns current the array numbers
@Avas77
Copy link

Avas77 commented Jul 9, 2023

I have a raised pr for this issue. Here is the pr link #813

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

2 participants