Simplified a bit of TypeScript code.

This commit is contained in:
Project Nayuki 2020-01-27 00:41:13 +00:00
parent ec65e32037
commit fd8720cd31
1 changed files with 2 additions and 6 deletions

View File

@ -572,12 +572,8 @@ namespace qrcodegen {
// Balance of black and white modules
let black: int = 0;
for (const row of this.modules) {
for (const color of row) {
if (color)
black++;
}
}
for (const row of this.modules)
black = row.reduce((sum, color) => sum + (color ? 1 : 0), black);
const total: int = this.size * this.size; // Note that size is odd, so black/total != 1/2
// Compute the smallest integer k >= 0 such that (45-5k)% <= black/total <= (55+5k)%
const k: int = Math.ceil(Math.abs(black * 20 - total * 10) / total) - 1;