Skip to content

Instantly share code, notes, and snippets.

@nkint
Created March 15, 2018 13:18
Show Gist options
  • Save nkint/255bb308e791b81473edbb02dbf3648a to your computer and use it in GitHub Desktop.
Save nkint/255bb308e791b81473edbb02dbf3648a to your computer and use it in GitHub Desktop.
Linked list validation
class Node {
constructor(id, prev, isValid) {
this.id = id
this.prev = prev
this.isValid = isValid
}
disabled() {
return this.isValid && (this.prev ? this.prev.disabled() : true)
}
}
const list = Array(6).fill(0).reduce((acc, n, i) => {
const prev = i === 0 ? null : acc[i - 1]
acc.push(new Node(i, prev, true))
return acc
}, [])
//console.log(list[5]);
console.log(list[5].disabled());
console.log('\n\n')
list[2].isValid = false
console.log(list[2])
console.log('\n\n')
console.log(list[5].disabled());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment