Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
(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
You can’t perform that action at this time.