숫자를 두개로 나눠서 두 합이 최소값이 되도록!
ex)num = 4325 => 59
We can split 4325 so that num1 is 24 and num2 is 35, giving a sum of 59. We can prove that 59 is indeed the minimal possible sum.
var splitNum = function(num) {
let arr=[...String(num)].map(num=> +num).sort((a,b)=>a-b)
let arr1=[]
let arr2=[]
for(let i in arr){
if(i % 2 ===1){
arr1.push(String(arr[i]))
}else{
arr2.push(String(arr[i]))
}
}
const num1=+arr1.map(num=>+num).join('')
const num2=+arr2.map(num=>+num).join('')
return num1+num2
};
let arr=[...String(num)].map(num=> +num).sort((a,b)=>a-b)
let arr1=[]
let arr2=[]
for(let i in arr){
if(i % 2 === 1){
arr1.push(String(arr[i]))
}else{
arr2.push(String(arr[i]))
}
}
const num1=+arr1.map(num=>+num).join('')
const num2=+arr2.map(num=>+num).join('')
return num1+num2