Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Second - after SaintDron review solution in Clear category for [old] Ground for the House by oduvan
"use strict";
const EMPTY = '0',
FILLED = '#';
function is_empty_line(line) {
return [ ...new Set(line) ].join('') === EMPTY;
}
function remove_empty_lines(lines) {
if (is_empty_line(lines[0])) {
return remove_empty_lines(lines.slice(1));
}
return lines;
}
function turn_lines(lines) {
return lines[0].map((_, c) => lines.map(r => r[c]));
}
function count_area(lines) {
return lines.length * lines[0].length;
}
function house(plan) {
if (plan.indexOf(FILLED) === -1) {
return 0;
}
let lines = plan.trim().split('\n').map(line=>line.split(''));
lines = remove_empty_lines(lines)
lines = remove_empty_lines(lines.reverse())
lines = turn_lines(lines)
lines = remove_empty_lines(lines)
lines = remove_empty_lines(lines.reverse())
return count_area(lines);
}
Sept. 8, 2018
Comments: