🔥 몰랐던 내용
[1일차]
📦 ~~(10 / 5)
몫을 구하는 과정에서 사용되는 방식으로 실수로 출력되지 않고 정수로 출력하기 위해서 사용함
~는 부정 연산자로써 bit가 1001인 수 5를 0110으로 뒤집는 역할을 해서 결과적으로 -(n + 1)의 값을 출력하는데 이러한 부정 연산자를 2번 사용함으로써 원래 값으로 돌리면 정수로 출력이 된다.
- Math.floor(10 / 5)와 동일한 역할을 한다.
[5일차]
📦 Array.reduce()
reduce()의 경우에는 초기값을 설정하지 않았을 때 문제점이 생긴다 그렇기 때문에 2번째 인자로 전달되는 초기값(이 문제에서는 0)을 설정하므로써 빈 값(짝수의 합을 구하는 과정 중 n = 1일 경우에는 빈 배열이 생성된다)에 대한 문제를 해결하기 위해 초기값을 설정해야한다.
[10일차]
📦 배열에서 홀수, 짝수 개수 구하기
function solution (number_list) {
let answer = [0, 0];
number_list.forEach((number)=> {
answer[number % 2] += 1
})
return answer
}
- 상당히 깔끔하게 구현된 코드라 생각되서 구현해보았다.