Created
June 9, 2015 18:05
-
-
Save johnboker/79bf81594023b4af666e 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
(function() { | |
var rows = map[0].length; | |
var cols = map.length; | |
String.prototype.replaceAt=function(index, character) | |
{ | |
return this.substr(0, index) + character + this.substr(index+character.length); | |
} | |
var dropRocks = function(c) | |
{ | |
for(var r = rows-1; r >= 0; r--) | |
{ | |
if(map[c][r] == 'o' && map[c][r+1] == '.') | |
{ | |
map[c] = map[c].replaceAt(r, '.'); | |
map[c] = map[c].replaceAt(r+1, 'o'); | |
r = rows-1; | |
} | |
} | |
} | |
var i = 0; | |
for(i = 0; i < cols; i++) | |
{ | |
dropRocks(i); | |
} | |
console.dir(map); | |
return map; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment