Created
January 17, 2018 01:35
-
-
Save gunn/794b19423ab89b52981650927ae524e5 to your computer and use it in GitHub Desktop.
This file contains 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
export default class LinkedList { | |
constructor(value, ...rest) { | |
this.value = value | |
if (rest.length) { | |
this.next = new LinkedList(...rest) | |
} | |
} | |
add(value) { | |
if (this.next) { | |
this.next.add(value) | |
} else { | |
this.next = new LinkedList(value) | |
} | |
} | |
has(value) { | |
return ( | |
this.value == value || | |
!!(this.next && this.next.has(value)) | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment