🔥 몰랐던 내용
[12일차]
📦 Array.reverse()
기존에 생각한 방법은 Array로 만드는 과정까지는 동일하다. 하지만 나는 pop()을 통해서 나온 값으로 새로운 배열을 만들어서 return
하려하였는데 이러한 방법을 쓰지않고 그냥 reverse()를 사용하면 자연스럽게 뒤집을 수 있다
- 영상에서는 Array(words)이런식으로 문자열로 만드는데 split()을 사용하는 방법도 있다고 말한다.
[14일차]
📦 s1과 s2의 유사도를 구하자
유사도를 구하는 문제에서 Array.filter()와 Array.includes()를 통해서 쉽게 구할 수가 있구나!!!
function solution(s1, s2) {
return s1.filter(v => s2.includes(v)).length
}
배열은 연산이 가능하다. Set을 통해 중복을 제거해서 새롭게 값을 출력할 수 있다.
function solution(s1, s2) {
return s1 + s2 - Set([...s1, ...s2]).size
}
[15일차]
📦 가위바위보 이기는 값 출력하기
각 상황마다 if문을 돌리는 것이 아니라 이런식으로 사용하면 되는데 map()을 사용하는 부분과 객체에 접근하는 방법에 대해서 좀 미숙했던 부분이 있었다. (바로 떠올리지 못함)
function solution (rsp) {
const oject = {
"r" : "p",
"s" : "r",
"p" : "s"
}
return [...rsp].map(v =>answer[v]).join('')
}
[16일차]
📦 stack과 queue
마지막을 빼는것 Array.pop() 처음을 빼는 것 Array.shift() 마지막에 더하는 것 Array.push() 처음에 더하는 것 Array.unshift()
(바로 떠올리지 못함)
number = [number.pop(), ...number], number = [...number.slice(1), number.shift()]
누가 먼저 실행되는지도 중요한 것 같다!!
[17일차]
📦 Array.from()
Array.from()의 매개변수로 arrayLike의 값이 들어가기 때문에 문자열은 가능하지만 number형태는 불가능하다 그렇기에 toString()을 거쳐서 문자열 형태로 만들어야 한다.
function solution (age) {
const chr = 'abcdefghij';
return Array.from(age.toString()).map(v => chr[v].join(''))
}