let arr = [12,30,45,62,79,88]; // 6 element inside the array
let arr2 = [6,4,5,2,1,1,2,3,6,5,4,5......]; // all elements are less than 6 and greater than 0
let temp = 50;
let sum = 0;
arr2
是一些数字的数组(所有数字的总和等于 100)。
现在我想执行一个操作,我必须将 arr2 元素相互添加,如果总和大于或等于 arr 的任何元素,那么我必须添加 30 和 temp。对于 arr 的每个元素,我都必须这样做。
示例
if sum >= 12(1st element of arr) then temp = temp + 30 (so now temp will be 80),
if sum >= 30(2nd element of arr) then temp = temp + 30 (so now temp will be 110),
if sum >= 45(3rd element of arr) then temp = temp + 30 (so now temp will be 140),......
if sum >= 88(last element of arr) then temp = temp + 30 (so now temp will be 230)