Timeline for answer to How can I insert an item into an array at a specific index? by Redu
Current License: CC BY-SA 4.0
Post Revisions
8 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Aug 21, 2021 at 11:55 | history | edited | Yashwardhan Pauranik | CC BY-SA 4.0 |
added 8 characters in body
|
| Aug 13, 2021 at 14:10 | history | edited | Peter Mortensen | CC BY-SA 4.0 |
Active reading.
|
| Dec 9, 2016 at 17:02 | comment | added | Geza Turi | I think it is worth mentioning that the rest parameter is new ECMA 6th (developer.mozilla.org/en/docs/Web/JavaScript/Reference/… ) | |
| Jun 2, 2016 at 14:18 | comment | added | NiKo | Your second implementation is the cleanest from this whole page and you have zero votes. Please take mine and keep up the good work. (you should just avoid mutating the prototype but you already know that) | |
| May 22, 2016 at 21:43 | history | edited | Redu | CC BY-SA 3.0 |
added 708 characters in body
|
| May 22, 2016 at 21:23 | comment | added | Redu | We are talking about insert here and the second parameter of Array.prototype.splice() has to be zero. And what it returns have no meaning other than "i have not deleted anything" and since we use it for inserting an item we already have that information. If you don't want to mutate the original array then you can do the same with two Array.prototype.slice() and one Array.prototype.concat() operations. It's up to you. | |
| May 22, 2016 at 21:15 | comment | added | chrisbajorin |
"a totally meaningless empty array" - it only returns an empty array when the second parameter is 0. If it's greater than 0, it returns the items removed from the array. Given that you're adding to a prototype, and splice mutates the original array, I don't think "proper functional programming" belongs anywhere in the vicinity of splice.
|
|
| May 13, 2016 at 23:22 | history | answered | Redu | CC BY-SA 3.0 |