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) 

Closed due to the fact that the essence of the issue is incomprehensible by the participants aleksandr barakin , Stepan Kasyanenko , Enikeyschik , Kromster , entithat January 24 at 12:33 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • show the original array though - Sasuke
  • one
    Is not an educational task an hour ?? - Sasuke
  • pretty simple task so that - Sasuke
  • and how the array looks from the map and the result in general is like doing nada from the condition that it is necessary from 1 to 9 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
  • var nutriscore = data ['nutriscore'] show the result of the assignment in the question how it looks, for example, put it into a console, expand the entities and make a screen - Sasuke

1 answer 1

Nails microscope:

 let data = [{ code: '123', nutriscore: 1 }, { code: '234', nutriscore: 1 }, { code: '345', nutriscore: 2 }, { code: '456', nutriscore: 2 }, { code: '567', nutriscore: 3 }, { code: '678', nutriscore: 2 }, ]; let db = new SQL.Database(); db.run('CREATE TABLE temp (code VARCHAR, nutriscore INT)'); data.forEach(item => db.run('INSERT INTO temp (code, nutriscore) VALUES (?, ?)', [item.code, item.nutriscore])); db.each('SELECT nutriscore, COUNT(*) AS cnt FROM temp GROUP BY nutriscore', row => document.write(`число ${row.nutriscore} == ${row.cnt} раз(а) <br>`)); 
 <script src="https://lovasoa.imtqy.com/sql.js/js/sql.js"></script> 

:)

  • one
    Plus with me for perversion))) - Stepan Kasyanenko