목록JAVASCRIPT (89)
Illie
개요 난 요즘 프로그래머스에서 알고리즘 문제를 풀고 있다. 사실 이전부터 알고리즘 공부를 항상 하다가 포기했었는데,,, 조금 강제성을 가질 필요가 있어서 알고리즘 스터디에 들어갔다 알고리즘 문제를 풀다보면 내가 이것도 모른다고? 혹은 못푼다고? 내가 이 함수를 제대로 이해하고 있던게 아닌가? 왜 늘 내 예상과 다르게 흘러갈까 뭐이런 생각과 자괴감과 내 자신에 대한 실망과...ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ 오늘 하루 찢었다 난리난다 뭐 이런 생각과 뿌듯함과 함께 어깨가 하늘까지 치솟는다 지금와서 글을 쓰면서 생각하는건데, 알고리즘은 내 정신에 좋지 않은거 같네 본문 - splice 내가 뭘 잘못알고있는 걸까 https://school.programmers.co.kr/learn/courses/30/lessons/..
개요 클린코드 자바스크립트 (장Poco) 강의 중 정리... 예시 1 클로저: 실행된 외부 함수로 인해, 내부 함수의 환경을 기억하는 것 function add(num1) { return function sum(num2) { return num1 + num2; } } const addOne = add(1); const addTwo = add(2); addOne(3) // 4 add(1)(3) // 4 예시 2 함수를 넘기는 것도 가능 function add(num1) { return function (num2) { return function (calculateFn) { return calculateFn(num1, num2); } } } function sum(num1, num2) { return num..
1. Computed Property Name 객체 key 값에 변수 넣는 것을 처리하는 방법 const prop = 'hello'; const obj = { [prop]: 123 }; console.log(obj) // 출력 값: {hello: 123} const funcName0 = 'func0'; const funcName1 = 'func1'; const funcName2 = 'func2'; const obj = { [funcName0]() { return 'func0'; } [funcName1]() { return 'func1'; } [funcName2]() { return 'func2'; } } for (let i = 0; i < 3; i++) { console.log(obj[`func${i}`..
1. typeof function myFunction(){} class MyClass {} const str = new String('문자열') typeof '문자열' --> 'string' typeof true --> 'boolean' typeof undefined --> 'undefined' typeof 123 --> 'number' typeof Symbol() --> 'symbol' typeof myFunction --> 'function' typeof MyClass --> 'undefined' typeof str --> 'object' typeof null --> 'object' (공식적으로 인정된 오류) 2. instanceof function Person(name, age) { this.nam..
1. 복습 type Nickname = string; type Health = number; type Friends = Array type Player = { nickname: string, healthBar: number } type Player2 = { nickname: Nickname, healthBar: Health } const nico:Player = { nickname: "nico", healthBar: 3 } type Food = string; const kimchi:Food = "delicious" 2. 정해진 값만 사용가능하게 type / interface 지정하기 type Team = "red" | "blue" | "yellow"; type Health = 1 | 5 | 10 type..
1. Class class Player { constructor( private firstName:string, private lastName:string, public nickName:string, ){} } const nico = new Player("nico", "las", "니코") // ERR(firstName은 private 이므로...) nico.firstName 2. Abstract class(추상클래스) - 다른 클래스가 상속받을 수 있는 클래스 - 직접 인스턴스 생성 불가능 abstract class User { constructor( private firstName:string, private lastName:string, public nickName:string, ){} } clas..
1. Call Signature // ERR -> a, b가 any타입이기 때문 function add(a, b){ return a + b; } // ALLOWED function add(a:number, b:number){ return a + b; } // ALLOWED const add = (a:number, b:number) => a+b // Call signatures type Add = (a:number, b:number) => number; const add:Add = (a,b) => a + b // Call signature 에러 조심 (중괄호) const add:Add = (a,b) => {a + b} // -> void 2. Overloading(오버로딩) 여러 개의 Call Signat..
0. 기본 type Age = number; type Name = string; type Player = { name: Name age?: Age } const playerMaker = (name: string): Player => ({name}) const nico = playerMaker("nico") nico.age = 12 // 항상 정해져있는 갯수의 요소를 가져오는 배열을 생성해야할 때 유용 const player: [string, number, boolean] = ["nico", 1, true]; player[0] = 1; // not allowed ([0]: string) const player: readonly [string, number, boolean] = ["nico", 1, true..