From ff5edc64acea82eb9b01a715db381e1290e8c2e3 Mon Sep 17 00:00:00 2001 From: Ladd Hoffman Date: Thu, 12 Jan 2023 09:03:54 -0600 Subject: [PATCH] Fix revaluation limit enforcement --- forum-network/src/classes/forum.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/forum-network/src/classes/forum.js b/forum-network/src/classes/forum.js index 0020392..dccea26 100644 --- a/forum-network/src/classes/forum.js +++ b/forum-network/src/classes/forum.js @@ -14,10 +14,10 @@ class Post extends Actor { this.value = 0; this.citations = postContent.citations; this.title = postContent.title; - this.totalCitationWeight = this.citations.reduce((total, { weight }) => total += weight, 0); - if (this.totalCitationWeight > params.revaluationLimit) { - throw new Error('Post total citation weight exceeds revaluation limit ' - + `(${this.totalCitationWeight} > ${params.revaluationLimit})`); + const revaluationTotal = this.citations.reduce((total, { weight }) => total += Math.abs(weight), 0); + if (revaluationTotal > params.revaluationLimit) { + throw new Error('Post revaluation total exceeds revaluation limit ' + + `(${revaluationTotal} > ${params.revaluationLimit})`); } if (this.citations.some(({ weight }) => Math.abs(weight) > 1)) { throw new Error('Each citation weight must be in the range [-1, 1]');