1.
function likes(names) {
if(names.length===0){
return "no one likes this";
}
if(names.length ===1){
return names[0] + " likes this"
}else if(names.length ===2){
return names[0] +" and " +names[1] + " like this";
}else if(names.length ===3){
return names[0] +", "+ names[1] +" and " +names[2] + " like this";
}else{
return names[0] +", "+ names[1] +" and " +(names.length-2) +" others"+ " like this";
}
}
2.
function findnb(m) {
// 역으로 생각해서 1³ + (n-1)³+(n-2)³+...+n³이런식으로 생각하면 편함.
let n = 1;
let total = 0;
while (total < m) {
total += Math.pow(n, 3);
if (total === m) {
return n;
}
n++;
}
return -1;
}
정보 감사합니다.