map, filter, reduce
map, filter, reduce const products = [ {name: '안녕', price: 12000}, {name: '하세요', price: 15000}, {name: '저는', price: 20000}, {name: '지니', price: 25000}, {name: '입니다', price: 15000} ]; map map 로직 const map = (f, iter) => {//f 라는 함수를 받아서 어떤값을 수집할 것인지 위임한다.(추상화) let res = []; for (const a of iter) { res.push(f(a)); } return res; }; 고차함수이다. /////////////es5 /////////////// let names = []; for (const ..
2021. 7. 5.
ES6 이터러블 /이터레이터, 리스트 순회
리스트 순회 기존 for(var i =0;i< str.length;i++){ ... } es6 for(const a of list){ ... } 간결하게 변경 되었음 이터러블/이터레이터 Array , Set, Map const arr = [1,2,3]; for(const a of arr){ } const set = new Set([1,2,3]); for(const a of set){ } const map = new Map(['a',1], ['b',2] , ['c',3]); for(const a of map){ } array 는 arr[0] , arr[1] 이렇게 해서 값을 찾을 수 있지만 Set과 Map은 불가능함 어떻게 for of문에서 동작이 되는가? Symbol.iterator es6에 추가된 sy..
2021. 7. 3.