From 0ddead2464f226774339f4d8a56c4145385dd7d2 Mon Sep 17 00:00:00 2001 From: zznidar Date: Sat, 12 Sep 2020 11:52:24 +0200 Subject: [PATCH] Fix issue #1 Certain sequences and rows threw an undefined error due to trying to access solution[-1] --- linear_partition.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linear_partition.js b/linear_partition.js index 75d667d..3bc9822 100644 --- a/linear_partition.js +++ b/linear_partition.js @@ -54,7 +54,7 @@ function linear_partition(seq, k) { } min = Math.min.apply(this, list_of_maxes); m = list_of_pairs.reduce(function(previous, current) { - return current[0] < previous[0] ? current : previous; + return current[0] <= previous[0] ? current : previous; }, [Infinity]); table[i][j] = m[0]; solution[i-1][j-1] = m[1];