From 64e58902ccce00c8a5d1c0ed125c2a29334b2b48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhani=20Krekel=C3=A4?= Date: Sat, 26 May 2018 21:58:18 +0300 Subject: [PATCH] Use reduce to find min and max instead of a loop --- gir.js | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/gir.js b/gir.js index 166ca36..bd2b3d8 100644 --- a/gir.js +++ b/gir.js @@ -943,16 +943,10 @@ function ircbotRun(program, input, maxCycles = 400000) { // Find min and max of the existant array indinces, since // there is no good way to easily get them and we need them // for the output - let min = Infinity; - let max = -Infinity; - for(let index of result.state.memory.keys()) { - if(index < min) { - min = index; - } - if(index > max) { - max = index; - } - } + let min = Array.from(result.state.memory.keys()).reduce( + (x, y) => Math.min(x, y)); + let max = Array.from(result.state.memory.keys()).reduce( + (x, y) => Math.max(x, y)); // Get 15 cells of context on each side of tape head // Exception is if max or min comes up before that, in which