Skip to content

Instantly share code, notes, and snippets.

@drakeirving
Created July 4, 2017 02:28
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 drakeirving/0456b9437b4f8a995e8f714b1b131800 to your computer and use it in GitHub Desktop.
Save drakeirving/0456b9437b4f8a995e8f714b1b131800 to your computer and use it in GitHub Desktop.
nd-array set
function ndset(a, inds, b){
if(length(inds) == 0){ return b; }
let temp = a;
temp[inds[0]] = ndset(a[inds[0]], inds[1..length(inds)], b);
return temp;
}
// let a = [[[0,1],[2,3]],[[4,5],[6,7]]];
// let b = ndset(a, [0,1,1], 8);
// b #=> [[[0,1],[2,8]],[[4,5],[6,7]]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment