Created
October 28, 2013 23:32
-
-
Save vslinko/7206675 to your computer and use it in GitHub Desktop.
matrix iterator written for collegue
This file contains hidden or 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
class MatrixIterator | |
positions: [] | |
constructor: (@arrays) -> | |
@reset() | |
reset: -> | |
@hasNext = true | |
for i in [[email protected]] | |
@positions[i] = 0 | |
next: -> | |
unless @hasNext | |
return null | |
result = [] | |
for i in [[email protected]] | |
result.push @arrays[i][@positions[i]] | |
@hasNext = false | |
for i in [[email protected]] | |
@positions[i] += 1 | |
if @positions[i] < @arrays[i].length | |
@hasNext = true | |
break | |
else | |
@positions[i] = 0 | |
result | |
it = new MatrixIterator [ | |
[11000254, 11000255, 11000256] | |
[11000257, 11000258] | |
[11000259, 11000260] | |
] | |
while combination = it.next() | |
console.log combination |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment