목록전체 글 (126)
코딩쌀롱
pr64061(doll_game).js (프로그래머스 64061문제 - 다른 풀이) 함수가 어떻게 실행되는지 이해하기 위해서 reduce, map 메서드, spread 연산자 학습. const transpose = matrix => matrix.reduce( (result, row) => row.map((_, i) => [...(result[i] || []), row[i]]), [] ); 📌 reduce() 두 번째 매개변수인 initialValue를 통해서 반환 값을 자유롭게 지정할 수 있다. (여러 자료형 가능) map, filter, find 함수로 구현할 수 있는 기능은 모두 reduce로도 가능하다. ✱ 매개변수 // initialValue는 optional arr.reduce(callback(..
✏️비동기(Asynchronous) 📌 예시 이해하기 ✱1번 function test() { let result = null; fetch('https://jsonplaceholder.typicode.com/todos/1') .then(response => response.json()) .then(json => result = json) return result; } test(); // null 서버와 통신(fetch)하는 일은 브라우저가 하는 일이니까 브라우저에게 보내고 다음 코드를 실행. 그래서 result에 원래 담겨져있던 null 반환. function test() { fetch('https://jsonplaceholder.typicode.com/todos/1') .then(response => r..
📌 addEventListener의 콜백함수 ✱문제 발생 // class TodoView 안에 있는 메서드 initEvent(todoViewObj) { // 콜백함수가 기명함수일 때 this.addButton.addEventListener("click", this.addList.bind(this)); // 콜백함수가 익명함수일 때 this.listWrapper.addEventListener("click", function({target}) { if(target.nodeName === 'LABEL') { todoViewObj.makeLineThrough(target); } if(target.nodeName === 'I') { todoViewObj.removeListItem(ta..