From fd8720cd316c0c7a4226ed52e825825de0fe7277 Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Mon, 27 Jan 2020 00:41:13 +0000 Subject: [PATCH] Simplified a bit of TypeScript code. --- typescript-javascript/qrcodegen.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/typescript-javascript/qrcodegen.ts b/typescript-javascript/qrcodegen.ts index 9b75c06..6480f4a 100644 --- a/typescript-javascript/qrcodegen.ts +++ b/typescript-javascript/qrcodegen.ts @@ -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;