Created
January 26, 2017 01:36
-
-
Save bbarrows/54206d599b9d84ebad5d6b60c46f4211 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
var arr = [4,5,6,7,8,9]; | |
for (var v of arr) { | |
console.log( v ); | |
} | |
// 4 5 6 7 8 9 | |
// define iterator that only produces values | |
// from odd indexes | |
arr[Symbol.iterator] = function*() { | |
var idx = 1; | |
do { | |
yield this[idx]; | |
} while ((idx += 2) < this.length); | |
}; | |
for (var v of arr) { | |
console.log( v ); | |
} | |
// 5 7 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment