Skip to content

Instantly share code, notes, and snippets.

@gunn
Created January 17, 2018 01:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gunn/794b19423ab89b52981650927ae524e5 to your computer and use it in GitHub Desktop.
Save gunn/794b19423ab89b52981650927ae524e5 to your computer and use it in GitHub Desktop.
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