Minimum Amount of Time to Fill Cups LeetCode solution in JavaScript
1var fillCups = function (amount) {2var count = 0;3var a = amount;4while (eval(a.join("+")) > 0) {5var max = Math.max(...a);6a.splice(a.indexOf(max), 1);7var max2 = Math.max(...a);8a.splice(a.indexOf(max2), 1);9count++;10if (max == 0) a.push(0);11else a.push(max - 1);12if (max2 == 0) a.push(0);13else a.push(max2 - 1);14}15return count;16};