
분류 전체보기

return 0보다 작은걸 반환한다.return > 0, B, A (switch order) 오름순서는 작은 숫자에서 큰 숫자로 가는 것 의미// Stringsconst owners = ['Jonas', 'Zach', 'Adam', 'Martha'];console.log(owners.sort());console.log(owners);//Numbersconsole.log(movements);// return 0, B, A (switch order)// Ascending/*movements.sort((a, b) => { // a-b임. if (a > b) return 1; // 긍정적 if (a a - b);// a가 b보다 클 경우 양수라는 걸 알고 있음// 즉, 양수 반환console.lo..

비슷하면서도 다른 some, evey, filter의 차이에 대해 알아보자! ✨const numbers = [1, 2, 3, 4, 5];some - 조건에 하나라도 맞으면 true 반환some은 배열에서 조건을 만족하는 요소가 하나라도 있으면 true를, 아니면 false를 반환한다.const hasEven = numbers.some(num => num % 2 === 0);console.log(hasEven); // true (짝수 2, 4가 있기 때문) 그렇다면 언제 사용할까? 🤔특정 조건을 충족하는 항목이 하나라도 있는지 확인할 때 유용하다.evey - 모든 요소가 조건에 맞으면 true반환every는 배열의 모든 요소가 조건을 만족해야 true를, 하나라도 불만족하면 false를 반환한다.cons..
자바스크립트에서 콜백함수의 개념에 대해 헷갈렸다. 콜백함수는 다른 함수의 파라미터로써 전달되는 함수라고 한다. 그렇다면 콜백함수가 왜? 필요할까? 콜백함수가 필요한 이유는 비동기 처리, 유연한 코드 구조를 위해서다.그렇다면 비동기 처리가 뭘까?자바스크립트에서는 코드가 위에서 아래로 순차적 실행이 된다. 그러나, 코드가 다른 행위가 일어난 뒤에 실행되는 경우도 있고 순차적으로 실행되지 않는 경우도 있다. 이럴때 비동기 프로그래밍이라고 한다. https://www.freecodecamp.org/korean/news/https-www-freecodecamp-org-news-javascript-callback-functions-what-are-callbacks-in-js-and-how-to-use-them/..

옵셔닝 체이닝(?.)객체의 속성이나 메서드가 존재하는지 확인 후 접근할 때 사용 만약 속성이 null 또는 undefind라면, 에러를 발생시키지 않고 undefined를 반환=> 안전하게 객체의 속성 접근 const user = { name: 'Alice', address: { city: 'New York', },};// 옵셔널 체이닝 없이:console.log(user.address.city); // 'New York'console.log(user.address.street); // undefined (정상 작동)console.log(user.phone.number); // TypeError: Cannot read property 'number' of undefined// 옵셔널 체이닝 사..

filter메서드함수의 바환 값을 true로 만드는 요소를 찾는다. find메서드배열에서 조건을 만족하느 첫번째 요소를 반환한다. filter 메서드와 find 메서드의 근본적인 2가지 차이filtera메서드는 조건에 일치하는 모든 요소를 반환하지만 find메서드는 첫 번째와 두번째만 반환한다.filter메서드는 새 배열을 반환하고 find메서드는 배열이 아닌 요소만 반환한다.

map()filter()reduce()목적배열 내의 모든 요소 대해서 주어진 함수를 호출한 결과를 모아 새로운 배열로 반환배열에서 조건을 만족하는 요소만 추려서 새로운 배열을 반환배열의 요소를 누적하여 단일값 만듦사용 예시배열의 각 요소를 평가한다.(평가한다: 특정 조건이나 연산을 적용해 판단하거나 처리하는 과정을 의미)배열의 각 요소를 평가하고, 조건에 맞는 요소들만 남김배열의 각 요소를 누적하거나 합산하여 하나의 값을 계산할 때 사용반환 값변환 된 요소로 구성된 새로운 배열조건을 만족하는 요소로 구성된 새로운 배열누적된 단일 값코드const numbers = [1, 2, 3, 4];const dubled = numbers.map(num=> num*2);console.log(doubled); // [2..

제 1장 Network Programming - Socket의 이해1. Network programming이란?network이란? Computer network각 host(end-system)을 연결하여 통신을 가능케하는 연결망host(end-system): pc, mobile기기, laptoppc(x)/ws(o)통신 sw 탑재 여부Internet(internetwork)network들이 연결됨연결장치(router, geteway, bridge, repeater)들이 필요함Ip(internet protocol) 이용 연결- ip addressClient/serverClient: 서버에 정보나 서비스를 요청하고 응답을 기다리는 hostServer: client의 요청을 폐기, 요청에 오면 서비스를 제..

문제문자열 s가 매개변수로 주어집니다. s에서 한 번만 등장하는 문자를 사전 순으로 정렬한 문자열을 return 하도록 solution 함수를 완성해보세요. 한 번만 등장하는 문자가 없을 경우 빈 문자열을 return 합니다.해결 과정문자를 사전순으로 정렬했다고 하니까 오름차순으로 정렬을 해야겠다고 생각했다.function solution(s) { var answer = ''; let sSort = s.split('').sort(); let emptyString = []; for(let i = 0; i 문제를 보고 이중for문을 이용하여 중복된 문자를 제외하고 중복되지 않은 문자를 추가하는 방향으로 생각을 했다.let sSort = s.split('').sort(); 는 문자열을 ..

for ... of 배열의 요소를 직접 반복for (const element of array)const array = [1, 2, 3];for (const element of array) { console.log(element); // 1, 2, 3}배열 분만 아니라 map, set, string, nodelist 같은 이터러블 객체도 반복 가능객체에서 사용 블가for ...each배열의 각 요소에 대한 제공된 함수를 호출array.forEach(function(element, index, array) {...})const array = [1, 2, 3];array.forEach(function(element) { console.log(element); // 1, 2, 3 // 1, 2, 3}); ..