CoffeeScriptRedux icon indicating copy to clipboard operation
CoffeeScriptRedux copied to clipboard

Array Splice to remove element

Open DavidSouther opened this issue 10 years ago • 4 comments

In CoffeeScript Redux, this does not compile:

arr = ['a', 'b', 'c']
idx = 1
arr[idx..idx] = []

http://michaelficarra.github.io/CoffeeScriptRedux/#try:arr%20%3D%20%5B'a'%2C%20'b'%2C%20'c'%5D%0Aidx%20%3D%201%0Aarr%5Bidx..idx%5D%20%3D%20%5B%5D%0A

In CoffeeScript, it compiles to

var arr, idx, _ref;

arr = ['a', 'b', 'c'];

idx = 1;

[].splice.apply(arr, [idx, idx - idx + 1].concat(_ref = [])), _ref;

Which has the effect of in-place removing the idx element from the array.

http://coffeescript.org/#try:arr%20%3D%20%5B'a'%2C%20'b'%2C%20'c'%5D%0Aidx%20%3D%201%0Aarr%5Bidx..idx%5D%20%3D%20%5B%5D%0A%0Aalert(arr)

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/1781204-array-splice-to-remove-element?utm_campaign=plugin&utm_content=tracker%2F33145&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F33145&utm_medium=issues&utm_source=github).

DavidSouther avatar Apr 22 '14 15:04 DavidSouther

NB if the answer is, "Don't use this syntax, use splice as it's intended", that's totes cool, but a mention of that in the know breaking changes would be :+1:

DavidSouther avatar Apr 24 '14 16:04 DavidSouther

+1 for making it work the same as it does in the original CoffeeScript

notslang avatar Jun 28 '14 19:06 notslang

It will, @slang800.

michaelficarra avatar Jun 29 '14 07:06 michaelficarra

When, @michaelficarra? The pulse for redux is looking mighty sparse.

DavidSouther avatar Jun 29 '14 12:06 DavidSouther