Fix for replacing the middle item in an Array

the provided code `styles[(styles.length - 1) / 2] = "Classics";` will replace the last item instead of the middle one. in order to fix that we need to change code like this : `styles[Math.floor((styles.length - 1) / 2)] = "Classics";`
This commit is contained in:
Amid Dadgar 2017-10-06 17:05:26 +03:30 committed by GitHub
parent cceb7cbcc8
commit 70d1d874f6

View file

@ -3,7 +3,7 @@
```js run
let styles = ["Jazz", "Blues"];
styles.push("Rock-n-Roll");
styles[(styles.length + 1) / 2] = "Classics";
styles[Math.floor((styles.length - 1) / 2)] = "Classics";
alert( styles.shift() );
styles.unshift("Rap", "Reggie");
```