Skip to content

Instantly share code, notes, and snippets.

@zdychacek
Last active February 15, 2017 20:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zdychacek/11138987 to your computer and use it in GitHub Desktop.
Save zdychacek/11138987 to your computer and use it in GitHub Desktop.
Negative array using Proxy
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