Created
March 15, 2018 13:18
-
-
Save nkint/255bb308e791b81473edbb02dbf3648a to your computer and use it in GitHub Desktop.
Linked list validation
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
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