Swamped with your writing assignments? Take the weight off your shoulder!
Submit your assignment instructions
Absolutely NO Chegg!
Fix the following code. In addition to your code, please provide a brief explanation of the problem and your solution.
~~~
#! /usr/bin/env node
‘use strict’;
var lineReader = require(‘readline’).createInterface({
input: require(‘fs’).createReadStream(‘value_freq.csv’)
});
var total = 0;
var sum = 0;
var average = 0;
# Broken code
lineReader.on(‘line’, function(line) {
var values = line.split(‘,’);
total += values[0]*parseInt(values[1]);
sum += parseInt(values[1]);
}).on(‘close’, function (res) {
average = total/sum;
});
console.log(average);
~~~