Created
January 27, 2019 10:15
-
-
Save hk-skit/c1c7f90e0d7267e9f875a0b5a081b363 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
/** | |
* 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