'Generate new order of numbers from array
I'm currently trying to generate a new order of numbers from a current array with numbers from 1 - 10.
For example, I have arrary like this:
data = [
{
0: 1,
1: 2,
2: 3,
3: 4,
4: 5,
5: 6
},
{
0: 1,
1: 2,
2: 3,
3: 4,
4: 5,
5: 8
}
]
And i'm trying to generate a new order from this array from numbers from 1 - 10.
For example: I want it to generate a new order like this:
0: 1,
1: 2,
2: 3,
3: 4,
4: 5,
5: 7 (The new number)
Where it checks the order of the array, and make a new order with numbers from 1 - 10
Solution 1:[1]
Make sure you have the same keys on both objects.
const data = [
{0: 1, 1: 2, 2: 3, 3: 4, 4: 5, 5: 6},
{0: 1, 1: 2, 2: 3, 3: 4, 4: 5, 5: 8},
]
getAverageValueOfMappingElements() {
const keys = Object.keys(data[0])
return [...keys].map(key => {
return (data[0][key] + data[1][key]) / 2
})
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Suresh Hemal |
