-2

let yammerConfig = JSON.parse(this.configService.getConfigSettings("yammerConfig"));

2 Answers2

0

I think you want something like...

var array = [ {left: 482.01, top: 76}, {left: 584.01, top: 177.01}, {left: 786, top: 157.01}, {left: 399, top: 382} ];

var maxLeft = 0, maxTop = 0;

array.forEach(e => {
    e.left > maxLeft && (maxLeft = e.left);
    e.top > maxTop && (maxTop = e.top);
});

console.log(maxLeft, maxTop);

Cleaner way with ES6:

var array = [ {left: 482.01, top: 76}, {left: 584.01, top: 177.01}, {left: 786, top: 157.01}, {left: 399, top: 382} ];

let { maxLeft, maxTop } = maxLeftAndMaxTop(array);
console.log("maxLeft: ", maxLeft, "maxTop: ", maxTop);

function maxLeftAndMaxTop(arr, maxLeft = 0, maxTop = 0) {
    arr.forEach(e => {
        e.left > maxLeft && (maxLeft = e.left);
        e.top > maxTop && (maxTop = e.top);
    });
    return { maxLeft, maxTop };
}
console.log(maxLeft, maxTop);
Faly
  • 12,529
  • 1
  • 16
  • 34
-1

If you are just looking to return the highest value, you can reduce the array and return the highest value for left or top. For example:

array = [{type: "rect", originX: "left", originY: "top", left: 482.01, top: 76},
{type: "rect", originX: "left", originY: "top", left: 584.01, top: 177.01},
{type: "rect", originX: "left", originY: "top", left: 786, top: 157.01},
{type: "path-group", originX: "left", originY: "top", left: 399, top: 382},
{type: "path-group", originX: "left", originY: "top", left: 623.01, top: 378.01},
{type: "circle", originX: "left", originY: "top", left: 103, top: 173}];

// Get left
array.reduce((result, item) => item.left > result ? item.left : result, 0); // => 786

// Get top
array.reduce((result, item) => item.top > result ? item.top : result, 0); // => 382

If you don't want to use ES6 syntax, you would use a normal function:

array.reduce(function(result, item) {
  return item.left > result ? item.left : result
}, 0);
Blake Simpson
  • 1,070
  • 6
  • 10