Skip to content

Commit 9584f46

Browse files
committed
fix: parse string before using it as argument
1 parent cb0e55d commit 9584f46

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/project-euler/008-largest-product-in-a-series/series-largest-product-naive.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@ const { readFileSync } = require('fs')
22

33
/**
44
* Parses the number text file as a number array.
5+
*
56
* @param {string} numTxtPath Path to text file containing the number.
67
* @returns {number[]} The number in the text file as a number array.
78
*/
89
const numTxtToNumArr = (numTxtPath) =>
910
readFileSync(numTxtPath, 'utf8')
1011
.split('')
11-
.filter(str => !/[\s]/.test(str) && !isNaN(str))
12+
.filter(str => !/[\s]/.test(str) && !isNaN(parseInt(str)))
1213
.map(str => parseInt(str))
1314

1415
/**
1516
* Computes the product of a sub-series in a number array.
17+
*
1618
* @param {number[]} numArr An array of numbers.
1719
* @param {number} index Index of the first number.
1820
* @param {number} scopeSize Size of the sub-series.
@@ -25,6 +27,7 @@ const getScopeProduct = (numArr, index, scopeSize) =>
2527

2628
/**
2729
* Computes the largest product in a series of numbers.
30+
*
2831
* @param {string} numTxtPath Path to text file containing the number.
2932
* @param {number} scopeSize Number of adjacent numbers to multiply.
3033
* @returns {number} Largest product in the series.

0 commit comments

Comments
 (0)