Use reduce to find min and max instead of a loop
This commit is contained in:
parent
27a13b7fac
commit
64e58902cc
14
gir.js
14
gir.js
|
@ -943,16 +943,10 @@ function ircbotRun(program, input, maxCycles = 400000) {
|
||||||
// Find min and max of the existant array indinces, since
|
// Find min and max of the existant array indinces, since
|
||||||
// there is no good way to easily get them and we need them
|
// there is no good way to easily get them and we need them
|
||||||
// for the output
|
// for the output
|
||||||
let min = Infinity;
|
let min = Array.from(result.state.memory.keys()).reduce(
|
||||||
let max = -Infinity;
|
(x, y) => Math.min(x, y));
|
||||||
for(let index of result.state.memory.keys()) {
|
let max = Array.from(result.state.memory.keys()).reduce(
|
||||||
if(index < min) {
|
(x, y) => Math.max(x, y));
|
||||||
min = index;
|
|
||||||
}
|
|
||||||
if(index > max) {
|
|
||||||
max = index;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get 15 cells of context on each side of tape head
|
// Get 15 cells of context on each side of tape head
|
||||||
// Exception is if max or min comes up before that, in which
|
// Exception is if max or min comes up before that, in which
|
||||||
|
|
Loading…
Reference in New Issue