분류 전체보기
-
[프로그래머스 level.1] filter , includes알고리즘 2023. 6. 20. 11:22
로또의 순위 function solution(lottos, win_nums) { let countZero = lottos.filter(x => x===0).length; //0의개수 let sameNum = lottos.filter(x => win_nums.includes(x)).length; //같은 개수 let num1 = 7 - (sameNum + countZero === 0 ? 1 : sameNum + countZero); let num2 = 7 - (sameNum === 0? 1 : sameNum); let answer = [num1, num2] return answer; } 쓰면서 생각이 든건데 변수명 작명을 좀 못하는 것 같다 나중에 다시 볼때 가독성을 높이기 위해서 조금은 고민하고 변수를 ..
-
[프로그래머스 level.1] 이중반복문, 중복제거, 정렬알고리즘 2023. 6. 20. 11:18
두개를 뽑아서 더하기 function solution(numbers) { let answer = []; for (let i = 0; i < numbers.length; i++) { for(let j = i + 1; j < numbers.length; j++) { answer.push(numbers[i] + numbers[j]); } } let result = [...new Set(answer)].sort(function(a, b) {return a - b;}); return result; } set을 활용하는것에 대해 선언을 간단하게 저렇게도 할 수 있다는 것을 알게 되었음 객체를 변수에 꼭 저장하지 않아도 호출만으로도 사용하는 법이 있구나 싶었음 sort() 관련되서는 항상 헷갈림 안에 수 정의를 하는..
-
[리액트를 다루는 기술] immer프로그래밍/React 2023. 6. 20. 00:09
immer은 언제 쓰이는가? spread연산자만으로는 깊은복사가 나왔을 때 제대로 대처하기 어렵다. 그래서 써야하는 게 이 immer라이브러리이다. 또한 전개연산자를 자주 사용하게 되면 가독성도 좋지 않아서 이러한 상황에서는 immer을 적극 활용해 보자. (깊은복사의 방법에서 immer함수가 쓰인다) import produce from 'immer'; const nextState = produce(originalState, draft => { darft.somewhere.deep.inside = 5//바꾸고싶은 값 }); 라이브러리이기때문에 따로 설치해야 함 yarn add immer 이 함수는 불변성 신경 안쓰는거 같아보여도 다 관리하는 게 특징임 원래 spread연산자 쓴 자리에 produce 갈아..
-
[CS Study] 스코프란 & 호이스팅이란 무엇일까???네트워크/CS Study 2023. 6. 19. 17:19
스코프란 무엇인가? 변수의 유효범위를 말하는 것이고 이 유효범위의 이해를 위해서 간단한 예제 코드를 보면서 알아보자. let greeting = 'Hello'; function greetSomeone(){ let firstName = 'KJ'; return greeting + ' ' + firstName; } console.log(greetSomeone()); // Hello KJ하위스코프는 상위스코프에 접근이 가능 // console.log(firstName); // 접근 불가능 상위스코프는 하위스코프에 접근 불가능 전역스코프 && 지역스코프 전역스코프는 가장 바깥에 있는 스코프를 가르키고 지역스코프는 전역스코프 외 스코프를 가리키는 말이다. 스코프체인 이러한 전역, 지역 스코프에 대한 개념이 함수와 ..