function solution(A,B){
var answer = 0;
const a = A.sort((a,b) => a - b)
const b = B.sort((a,b) => b - a)
for(let i = 0; i < A.length; i++){
answer += a[i] * b[i]
}
return answer;
}
function solution(A,B){
A.sort((a, b) => a - b)
B.sort((a, b) => b - a)
return A.reduce((total, val, idx) => total + val * B[idx], 0)
}
function solution(A,B){
var answer = 0;
const a = [...A];
const b = [...B];
let maxA = 0;
let minB = 0;
for(let i = 0; i < A.length; i++){
if(a.length === 1) {
maxA = Number(a)
minB = Number(b)
answer += maxA * minB
} else{
maxA = Math.max(...a)
minB = Math.min(...b)
answer += maxA * minB
}
a.splice(a.indexOf(maxA),1);
b.splice(b.indexOf(minB),1);
}
return answer;
}
reduce같은 고차함수를 계속 사용해보는 습관을 들여보자~!