https://school.programmers.co.kr/learn/courses/30/lessons/120868
function solution(sides) {
sides.sort((a, b) => a - b);
let h = sides[0] + sides[1] - 1;
let l = sides[1] - sides[0] + 1;
return h - l + 1;
}
다른 사람 풀이 😇
function solution(sides) {
return Math.min(...sides) * 2-1
}
https://school.programmers.co.kr/learn/courses/30/lessons/120838
function solution(letter) {
let result = letter.split(' ')
let answer = ''
morse = {
'.-':'a','-...':'b','-.-.':'c','-..':'d','.':'e','..-.':'f',
'--.':'g','....':'h','..':'i','.---':'j','-.-':'k','.-..':'l',
'--':'m','-.':'n','---':'o','.--.':'p','--.-':'q','.-.':'r',
'...':'s','-':'t','..-':'u','...-':'v','.--':'w','-..-':'x',
'-.--':'y','--..':'z'
}
for(let i = 0; i < result.length; i++){
answer += morse[result[i]]
}
return answer
}
https://school.programmers.co.kr/learn/courses/30/lessons/120923
function solution(num, total) {
var answer = [];
let sum =0;
let val = parseInt((total / num)); //3
let i = 0;
for(let j = 0; j < num / 2 + 1; j++){
for(i = 0; i < num; i++){
sum += val;
val += 1;;
}
if(sum==total){
for(i= num-1 ; i >= 0; i--){
answer[i] = val - 1;
val-=1;
}
break;
}
else{
val= val-num - 1;
sum=0;
}
}
return answer;
}
다른 사람 풀이 so 간단
function solution(num, total) {
var min = Math.ceil(total/num - Math.floor(num/2));
var max = Math.floor(total/num + Math.floor(num/2));
return new Array(max-min+1).fill(0).map((el,i)=>{return i+min;});
}
Array.fill()
Math.ceil()
Math.floor()
Array() 생성자
map()
https://school.programmers.co.kr/learn/courses/30/lessons/120808
//최대 공약수를 구하고 해당 값으로 분자, 분모를 나눠서 출력하기
function solution(numer1, denom1, numer2, denom2) {
let a = numer1 * denom2 + numer2 * denom1
let b = denom1 * denom2
let maximum = 1
for (let i = 1; i <= a; i++) {
if(a % i === 0 && b % i === 0) {
maximum = i
}
}
return [a / maximum, b / maximum]
}