All posts by stackoverflow

Iterating over an array of objects, summing values with the same index, and returning a new array of objects

I have an array of objects, something like this:

const data = [                 // array1
  [{x: 1}, {y:2}, {z:3}], 
  [{x: 1}, {y:2}, {z:3}],
  [{x: 1}, {y:2}, {z:3}]
],[                            // array2
  [{x: 1}, {y:2}, {z:3}], 
  [{x: 1}, {y:2}, {z:3}],
  [{x: 1}, {y:2}, {z:3}]
]

What needs to be accomplished is summing x from the array1 with x from the array2 that have the same index. Same goes for y and z. The final result should be a new array of objects containing the summed values.

Something like this:

[
  [{totalXOne: 2}, {totalYOne: 4}, {totalZOne: 6}],
  [{totalXTwo: 2}, {totalYTwo: 4}, {totalZTwo: 6}],
  [{totalXThree: 2}, {totalYthree: 4}, {totalZThree: 6}],
]

Note: All arrays are the same length, and if a value is missing it will be replaced with 0)

I found something nice on MDN, but it’s summing all x, y, z values, and it’s returning single summed values, like this:

let initialValue = 0;
let sum = [{x: 1}, {x:2}, {x:3}].reduce(function(accumulator,currentValue) {
    return accumulator + currentValue.x;
}, initialValue)

read more

SSRS lookup returning blank or skipping rows even though data is available in those fields

I have lookup expression to compare two datasets, the lookup is missing certain rows. Some rows in Totaldownload in DataSetCount have value of that data , but lookup is skipping. Some rows are lookup correctly why some were skipped. I am not sure if anyone has encountered this problem before where lookup is just returning blank to some rows in the column. please see image below ….

read more

php alice consecutive stones

I have to find a php code to solve a math problem.

A and B are playing a game of stones. A start always the game.
They will pick in turns 2 consecutive stones from a line until there are no consecutive stones –> condition1: stone i and stone i+1, where 1 ≤ i ≤ N−1

The line has N stones and are indexed from 1 to N. Condition2: N (1 ≤ N ≤ 10 000 000)

read more