In Cofffeescript, there are 2 built-in sytanxes for interation. for .. of .. / for .. in .. (by ..)
In Pragmatic Coffeescript book, the author says,
" Why have a seperate syntax? Why not just use for key, value of array?Because there're nothing stopping an array from having extra methods or data. If you want the whole shebang, then sure, use of. But if you just want to treat the array as an array, use in -- you will onlyget array[0], array[1], etc., up to array[array.length-1], in that order"
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
#============ | |
entries = [5, 2, 4, 6, 8] | |
highstBid = 0 | |
for bid of entries when bid > highstBid | |
highstBid = bid | |
console.log highstBid #return 4 | |
#============ | |
entries = [5, 2, 4, 6, 8] | |
highstBid = 0 | |
for bid in entries when bid > highstBid | |
highstBid = bid | |
console.log highstBid #return 8 |