1
0
mirror of https://github.com/psychopy/psychojs.git synced 2025-05-13 09:08:12 +00:00

js/util: tweak toNumerical() to match JSDoc comment

This commit is contained in:
Sotiri Bakagiannis 2020-10-13 19:45:16 +01:00
parent 581acf18aa
commit a3829c016a

View File

@ -259,22 +259,26 @@ export function toNumerical(obj)
return obj; return obj;
} }
if (typeof obj === 'string') const convertToNumber = (input) =>
{ {
obj = [obj]; const n = Number.parseFloat(input);
}
if (Array.isArray(obj))
{
return obj.map(e =>
{
let n = Number.parseFloat(e);
if (Number.isNaN(n)) if (Number.isNaN(n))
{ {
throw `unable to convert ${e} to a number`; throw `unable to convert ${e} to a number`;
} }
return n; return n;
}); }
if (typeof obj === 'string')
{
return convertToNumber(obj);
}
if (Array.isArray(obj))
{
return obj.map(convertToNumber);
} }
throw 'unable to convert the object to a number'; throw 'unable to convert the object to a number';