-
-
Save gilesbowkett/1171549 to your computer and use it in GitHub Desktop.
why does this CoffeeScript not accurately translate this Ruby?
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
insert: (ball, column) -> | |
for row in @rows when row[column] is null | |
row[column] = ball | |
return |
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
def insert(ball, column) | |
@grid.each do |row| | |
next unless row[column].nil? | |
row[column] = ball | |
return | |
end | |
end |
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
it 'avoids "collisions" on insert', -> | |
@grid = new Grid | |
@ball = new Ball 1 | |
@ball2 = new Ball 2 | |
@grid.insert @ball, 0 | |
@grid.insert @ball2, 0 | |
expect(@grid.contents(0, 0)).toEqual(@ball) | |
expect(@grid.contents(0, 1)).toEqual(@ball2) | |
expect(@grid.contents(0, 2)).toEqual(null) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment