# This bugs needs to be fixed

**URL:** https://es.discourse.group/t/this-bugs-needs-to-be-fixed/1667
**Category:** 💡 Ideas
**Created:** [March 30, 2023, 11:04am UTC](https://es.discourse.group/t/this-bugs-needs-to-be-fixed/1667 "2023-03-30T11:04:54Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![jaroslav.tavgen](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/jaroslav.tavgen/32/2732_2.png) [@jaroslav.tavgen](https://es.discourse.group/u/jaroslav.tavgen)
#### Post date: [March 30, 2023, 11:04am UTC](https://es.discourse.group/t/this-bugs-needs-to-be-fixed/1667/1 "2023-03-30T11:04:54Z")

</div>

```javascript
[1,2,3,4,5].slice(-([1,2,3,4,5].length-1)) // [2,3,4,5]
[1,2].slice(-([1,2].length-1)) //[2]
[1].slice(-([1].length-1)) // You would think []? No: [1]!

```

Syntax sugar (which is the ability to use "substr" with a minus sign) is supposed to help the developer, not to confuse him with inconsistent logics.

The solution could be simple:

```javascript
[1,2,3,4,5].slice(0) // [1,2,3,4,5];
[1,2,3,4,5].slice(-0) // [];

```

---

<div class="post-metadata">

### Author: ![aclaymore](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/aclaymore/32/501_2.png) [@aclaymore](https://es.discourse.group/u/aclaymore)
#### Post date: [March 30, 2023, 11:18am UTC](https://es.discourse.group/t/this-bugs-needs-to-be-fixed/1667/2 "2023-03-30T11:18:13Z")

</div>

The risk of changing this now is that there could be existing code that relies of both 0 and -0 having the same behavior. Generally speaking ECMAScript tired to remain backwards compatible so that older websites continue to work in newer browsers.

For the example why not:

```javascript
[1,2,3,4,5].slice(1) // [2,3,4,5]
[1,2].slice(1) // [2]
[1].slice(1) // []

```

---

<div class="post-metadata">

### Author: ![jaroslav.tavgen](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/jaroslav.tavgen/32/2732_2.png) [@jaroslav.tavgen](https://es.discourse.group/u/jaroslav.tavgen)
#### Post date: [March 30, 2023, 11:24am UTC](https://es.discourse.group/t/this-bugs-needs-to-be-fixed/1667/3 "2023-03-30T11:24:00Z")

</div>

Your solution is good, but what's the point of using substr with a minus sign if we need to switch to the plus one in order to ensure the stable work of the program? Maybe the usage of minus sign should be discouraged (while being allowed for backwards compatibility)?

---

<div class="post-metadata">

### Author: ![theScottyJam](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/thescottyjam/32/616_2.png) [@theScottyJam](https://es.discourse.group/u/theScottyJam)
#### Post date: [March 30, 2023, 3:59pm UTC](https://es.discourse.group/t/this-bugs-needs-to-be-fixed/1667/4 "2023-03-30T15:59:17Z")

</div>

The minus signs work great and are very convenient if you're dealing with numeric literals. If you're not dealing with literals, and are instead trying to autogenerated the index from a different number, the. Yeah, you need to watch out for the zero case.

---

<div class="post-metadata">

### Author: ![aclaymore](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/aclaymore/32/501_2.png) [@aclaymore](https://es.discourse.group/u/aclaymore)
#### Post date: [March 30, 2023, 5:06pm UTC](https://es.discourse.group/t/this-bugs-needs-to-be-fixed/1667/5 "2023-03-30T17:06:21Z")

</div>

Yeah, for example when wanting the last two values:

```javascript
[1,2,3,4,5].slice(-2) // [4,5]
[1,2].slice(-2) // [1,2]
[1].slice(-2) // [1]

```

---

<div class="post-metadata">

### Author: ![ljharb](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/ljharb/32/8_2.png) [@ljharb](https://es.discourse.group/u/ljharb)
#### Post date: [March 30, 2023, 9:52pm UTC](https://es.discourse.group/t/this-bugs-needs-to-be-fixed/1667/6 "2023-03-30T21:52:58Z")

</div>

(you keep using the term “substr”, which doesn’t apply to arrays - this is “slice”)
