-
-
Save kevin-ashton/7cad73c1846b745a0181 to your computer and use it in GitHub Desktop.
arrayTransform
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
//Transforms array a into the value of b while maintaining the original reference of a. Useful for updating synced arrays | |
function arrayTransform(a,b){ | |
var old = a.slice(); | |
b.forEach(function(i){ | |
if(a.indexOf(i) === -1){ | |
a.push(i); | |
} | |
}); | |
old.forEach(function(i){ | |
if(b.indexOf(i) === -1){ | |
var k = a.indexOf(i); | |
a.splice(k,1); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment