-
-
Save nathanhannig/b4276956a2f56901947b31aa23d1ffa2 to your computer and use it in GitHub Desktop.
Iteration & Iterable Protocol Quiz
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
const james = { | |
name: 'James', | |
height: `5'10"`, | |
weight: 185, | |
[Symbol.iterator]: function() { | |
const object = this; | |
const keys = Object.keys(object); | |
let index = 0; | |
return { | |
next: () => { | |
const key = keys[index]; | |
index++; | |
return { value: object[key], key: key, done: !(index < keys.length) }; | |
} | |
}; | |
} | |
}; | |
let iterator = james[Symbol.iterator](); | |
console.log(iterator.next().value); // 'James' | |
console.log(iterator.next().value); // `5'10` | |
console.log(iterator.next().value); // 185 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment