목록Coding Test (61)
undefined

문제 설명 문제 풀이 function solution(arr1, arr2) { let answer = [] for(let i = 0; i i가 0일때 j는 0,1 // i가 1일때 j는 0,1 2. 변수는 총 2개 arr1[i][j] => 중첩 for루프 이용 3. push로 배열에 넣어주기 개선 사항

문제 설명 문제 풀이 process.stdin.setEncoding('utf8'); process.stdin.on('data', data => { const n = data.split(" "); const a = Number(n[0]), b = Number(n[1]); const line = "*".repeat(a) for(let i = 0; i < b; i++) { console.log(line) } 1. reapet()으로 한 줄만들기 2. for루프로 출력반복 개선 사항

문제 설명 문제 풀이 function solution(x) { let arr = Array.from(`${x}`).map(Number) let total = 0 for(element of arr) { total = total += element } return x % total ? false : true } 1.from으로 배열화 이후 map을 이용하여 숫자 배열로 변경 2. for of Loop이용하여 내부 배열 요소들의 총 합을 구함 3. 하샤드의 수인지 판별 개선 사항

문제 설명 문제 풀이 function solution(num) { let attempt = 0 while (num !== 1) { if(attempt === 500) { return -1 } num = num % 2 ? num*3+1 : num/2 attempt++ } return attempt } 1. while loop 이용하여 num이 1이 될때 까지 반복 2. attempt 500번 넘어가는 수는 -1 리턴 3. 콜라츠 추측을 한번 거친 수를 다시 num에 배당 4. 시도 1+ 개선 사항

문제 설명 문제 풀이 function solution(n){ arrayN = Array.from(`${n}`).map(Number) return arrayN.reduce((prev,curr) => prev+curr) } 1. from()으로 배열화 2. map(Number)로 숫자화 3. reduce()로 전체의 합 계산 개선 사항