There is an array, let's say this:
var arr = [// Кол-во | множитель ['12', '2'], ['20', '3'], ['2, '1'] ]; Is it possible to count like this:
(12 * 2) + (20 * 3) + (2 * 1)
And get the result in a variable, let's say:
var arrsum = *result* //86 There is an array, let's say this:
var arr = [// Кол-во | множитель ['12', '2'], ['20', '3'], ['2, '1'] ]; Is it possible to count like this:
(12 * 2) + (20 * 3) + (2 * 1)
And get the result in a variable, let's say:
var arrsum = *result* //86 let arr = [// Кол-во | множитель ['12', '2'], ['20', '3'], ['2', '1'] ]; console.info(arr.map(a => a.reduce((a, c) => a * +c, 1)).reduce((a, c) => a + c, 0)); Oh, how many answers at once.
I will not delete myself!
var arr = [// Кол-во | множитель ['12', '2'], ['20', '3'], ['2', '1'] ]; console.log( arr.reduce((res, item) => res + item[0]*item[1], 0) ); var arr = [ ['12', '2'], ['20', '3'], ['2', '1'] ]; var m = arr.map(function(x) { return parseInt(x[0]) * parseInt(x[1]); }); var arrsum = m.reduce(function(acc, val) { return acc + val; }); console.log(arrsum); Source: https://ru.stackoverflow.com/questions/840768/
All Articles