Skip to content

Instantly share code, notes, and snippets.

@bitnom
Created July 18, 2019 15:00
Show Gist options
  • Save bitnom/fa80a3a099fb4b73df7c39c793f658a8 to your computer and use it in GitHub Desktop.
Save bitnom/fa80a3a099fb4b73df7c39c793f658a8 to your computer and use it in GitHub Desktop.
set if unique
function setu(node, item){
let unique = true
node.map().once(function (data) {
let aProps = Object.getOwnPropertyNames(data);
let bProps = Object.getOwnPropertyNames(item);
// number of properties
if (aProps.length === bProps.length) {
console.log("same len")
for (let i = 0; i < aProps.length; i++) {
let propName = aProps[i];
// values of same property
if (a[propName] === b[propName]) {
console.log("match")
unique = false
}
}
}
})
.then(function(){
if(unique){
node.set(item)
}
console.log(unique)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment