trekhleb / trekhleb/javascript-algorithms
feat:linked list add new method
Open
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 197k
- Forks
- 31k
- PR merge metrics
- No merged PRs in 30d
Description
traverse linked list is easy but uninteresting. You must add new variable and use while.So why not add a method to return a iterator.Then we can use for of to traverse. eg:
getIterator() {
const _this = this
return {
*[Symbol.iterator]() {
let currentNode = _this.head
if (!currentNode) yield node
while (currentNode) {
yield currentNode.value
currentNode = currentNode.next
}
}
}
}
use
const iter = linkedList.getIterator()
for(const item of iter){
console.log(item)
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names no implementation file or test. Locate the linked-list implementation and its existing traversal-related tests, then review how iteration is currently exposed. Done means the linked list supports the proposed iterator and for-of traversal, with behavior verified for populated and empty lists.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- data
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100