Skip to content

Instantly share code, notes, and snippets.

@johnboker
Created June 9, 2015 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnboker/79bf81594023b4af666e to your computer and use it in GitHub Desktop.
Save johnboker/79bf81594023b4af666e to your computer and use it in GitHub Desktop.
(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