From a3829c016a864ff153b15098075bd1586b4d04e9 Mon Sep 17 00:00:00 2001 From: Sotiri Bakagiannis Date: Tue, 13 Oct 2020 19:45:16 +0100 Subject: [PATCH] js/util: tweak toNumerical() to match JSDoc comment --- js/util/Util.js | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/js/util/Util.js b/js/util/Util.js index b93ad8d..ee75dc9 100644 --- a/js/util/Util.js +++ b/js/util/Util.js @@ -259,22 +259,26 @@ export function toNumerical(obj) return obj; } + const convertToNumber = (input) => + { + const n = Number.parseFloat(input); + + if (Number.isNaN(n)) + { + throw `unable to convert ${e} to a number`; + } + + return n; + } + if (typeof obj === 'string') { - obj = [obj]; + return convertToNumber(obj); } if (Array.isArray(obj)) { - return obj.map(e => - { - let n = Number.parseFloat(e); - if (Number.isNaN(n)) - { - throw `unable to convert ${e} to a number`; - } - return n; - }); + return obj.map(convertToNumber); } throw 'unable to convert the object to a number';