Sawtaytoes
3/9/2019 - 7:33 AM

Real Iterator Example

const createIterator = (
  array,
) => {
  let index = -1
  
  const next = () => {
    index = index + 1
    
    return (
      index < array.length
      ? {
        done: false,
        value: array[index],
      }
      : {
        done: true,
        value: undefined,
      }
    )
  }
  
  return {
    [Symbol.iterator]: () => ({
      next,
    }),
  }
}
const array = [1, 2, 3]

Array
.from(
  createIterator(
    array
  )
)
// [1, 2, 3]