Skip to content

Instantly share code, notes, and snippets.

@kageurufu
Created June 3, 2015 16:24
Show Gist options
  • Save kageurufu/0b33f6edd7ba71512d67 to your computer and use it in GitHub Desktop.
Save kageurufu/0b33f6edd7ba71512d67 to your computer and use it in GitHub Desktop.
devdating.net solution
return map.map(function(column_str) {
var col = column_str.split(""),
y = col.length;
while(y >= 0) {
if (col[y] == 'o' && col[y + 1] === '.') {
col[y + 1] = col[y];
col[y] = '.';
y++;
} else y--;
}
return col.join("");
});
@kubi
Copy link

kubi commented Jun 9, 2015

i did something similar:

(function() {
    function dropStones(row) {
        for (i = row.length-2; i >= 0; i--) {
            if (row[i] === 'o') {
                var tmpI = i;
                while(row[tmpI + 1] === '.') {
                    row[tmpI] = '.';
                    row[++tmpI] = 'o';
                }
            }
        }
        return row.join("");
    }

    map.forEach(function(row, y) {
        map[y] = dropStones(row.split(''));
    });

    return map;
})();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment