Skip to content

Instantly share code, notes, and snippets.

@hk-skit
Created January 27, 2019 10:15
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 hk-skit/c1c7f90e0d7267e9f875a0b5a081b363 to your computer and use it in GitHub Desktop.
Save hk-skit/c1c7f90e0d7267e9f875a0b5a081b363 to your computer and use it in GitHub Desktop.
/**
* Iterator function.
*
* @returns
* @memberof LinkedList
*/
[Symbol.iterator]() {
let current = this.head;
const iterable = {
next: () => {
if (current === null) {
return {
done: true
};
}
const {
value,
next
} = current;
current = next;
return {
value,
done: false
};
}
};
return iterable;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment