Write a function named sumOf2020
that accepts a string representing a file name as a parameter, reads the given file, finds the two numbers in that file that sum to exactly 2020, and returns the product of those numbers.
The file will contain exactly one non-negative integer per line.
For example, if the file named numbers.txt
contains the following values:
1721
979
366
299
675
1456
The two entries that sum to 2020 are 1721
and 299
.
Multiplying them together produces a product of 1721 * 299 = 514579
, so the call of sumOf2020("numbers.txt")
should return 514579
.
You may assume that the file exists and is readable,
that it follows the format described above,
and that there will be exactly one pair of values in the file that sum to 2020.
NOTE: You can read the entire contents of a file as a string by calling fs.readFileSync(filename)
.