Last active
February 15, 2017 20:13
-
-
Save zdychacek/11138987 to your computer and use it in GitHub Desktop.
Negative array using Proxy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function negArray (arr) { | |
return Proxy.create({ | |
get: function (rcvr, index) { | |
index = +index; | |
return arr[index < 0? arr.length + index : index]; | |
}, | |
set: function (rcvr, index, value) { | |
index = +index; | |
return arr[index < 0? arr.length + index : index] = value; | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment