6 kyu
Create iterator
2,206OlegBilykPro
Description:
Task
Implement an iterator
which receives an array of values, and returns an object with:
- a function
next
- a number
index
A call to the next
function should return an object with 2 attributes:
value
(the next value in the input array;undefined
if the value is not present or the array has been fully processed)done
(boolean which specifies whether the input array has been fully processed)
Accessing the index
attribute should return the index of the value currently held by the iterator
.
Example:
const iterator = createIterator(['One', , 'Two']);
iterator.index // 0
iterator.next() // { value: 'One', done: false }
iterator.index // 1
// A hole in the array - value is undefined
iterator.next() // { value: undefined, done: false }
iterator.index // 2
iterator.next() // { value: 'Two', done: false }
iterator.index // 3
// Iteration has finished - value is undefined, done becomes true
iterator.next() // { value: undefined, done: true }
iterator.index // 3
// Subsequent calls to next of a fully processed iterator don't change anything
iterator.next() // { value: undefined, done: true }
iterator.index // 3
Fundamentals
Arrays
Similar Kata:
Stats:
Created | Feb 25, 2019 |
Published | Feb 25, 2019 |
Warriors Trained | 2814 |
Total Skips | 13 |
Total Code Submissions | 8095 |
Total Times Completed | 2206 |
JavaScript Completions | 2206 |
Total Stars | 22 |
% of votes with a positive feedback rating | 89% of 118 |
Total "Very Satisfied" Votes | 98 |
Total "Somewhat Satisfied" Votes | 15 |
Total "Not Satisfied" Votes | 5 |
Total Rank Assessments | 11 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 8 kyu |