function InsertUpdateArray(arr, newItem, keyProperty) {

  let updated = false;

  const newArr = arr.map(item => {

    if (item[keyProperty] === newItem[keyProperty]) {

      updated = true;

      return { ...item, ...newItem }; // Merge new item properties with existing

    }

    return item;

  });



  if (!updated) {

    newArr.push(newItem); // Add new item if not found

  }

  return newArr;

}

/*

function InsertUpdateArray(arr, itemToUpsert) {

  let isNew = true;



  const newArray = arr.map(item => {

    if (item.sku === itemToUpsert.sku) {

      isNew = false;

      return { ...item, ...itemToUpsert }; // Update

    }

    return item;

  });



  if (isNew) {

    newArray.push(itemToUpsert); // Add new item

  }



  return newArray;

}

*/