IT General
Codility #6-MaxProductOfThree
SoftArts
2018. 9. 30. 18:19
function solution(A) {
let sorted = Array.from(A).sort((a, b) => a - b);
return Math.max(
sorted[0] * sorted[1] * sorted[2],
sorted[0] * sorted[1] * sorted[sorted.length - 1],
sorted[0] * sorted[sorted.length - 2] * sorted[sorted.length - 1],
sorted[sorted.length - 3] * sorted[sorted.length - 2] * sorted[sorted.length - 1]
);
}