there is an array of data, we need two columns: the code and the nutriscore of the product. The value in nutriscore is the digit {1, ..., 9}. for each nutriscore (from 1 to 9) it is necessary to count the number of products (number of codes in the code column).
d3.tsv("products_only_breads.tsv", function(error, data) { if (error) throw error; var nutriscore = data['nutriscore'] var product_amount=[] nutriscore.forEach(function(a){ product_amount[a] = product_amount[a] + 1 || 1; }); for (var key in product_amount) document.write('число ' + key + ' == ' + product_amount[key] + ' раз(а) <br>'); console.log(product_amount)
for (let i = 0; i < 9; i++) { result.push({ nutriscore: i, count: Y.filter(v => v.nutriscore == i).length }); }for (let i = 0; i < 9; i++) { result.push({ nutriscore: i, count: Y.filter(v => v.nutriscore == i).length }); }- Sasuke