Skip to content

Instantly share code, notes, and snippets.

@kevin-ashton
Created September 4, 2015 16:54
Show Gist options
  • Save kevin-ashton/7cad73c1846b745a0181 to your computer and use it in GitHub Desktop.
Save kevin-ashton/7cad73c1846b745a0181 to your computer and use it in GitHub Desktop.
arrayTransform
//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