본문 바로가기

---- Contents ----164

Array Method describe("Array Method에 관하여", function() { it("'filter' method에 관해 학습합니다.", function() { // filter => 조건을 줄 때 사용하면 편의함. 원본은 건드리지 않음. let numbers = [1, 2, 3]; let odd = numbers.filter(function(x) { return x % 2 !== 0; // 홀수 뽑기 }); expect(odd).toEqual([1, 3]); // true, false, true => true값만 return expect(odd.length).toBe(2); expect(numbers.length).toBe(3); }); it("'map' method에 관해 학습합니다.", functio.. 2020. 1. 21.
reduce & map & filter & every & some reduce로 다 만들 수 있다. (map & filter) const oneTwoThree = [1, 2, 3]; let result = oneTwoThree.map((v) => { console.log(v); return v; }); // 콘솔에는 1, 2, 3이 찍힘 oneTwoThree; // [1, 2, 3] result; // [1, 2, 3] oneTwoThree === result; // false result = oneTwoThree.map((v) => { return v + 1; }); result; // [2, 3, 4] *** map => 규칙적인 배열만 반환할 수 있는게 아니라, 함수 안에 적어준대로 반환할 수 있기 때문에 자유도가 높다. result = oneTwoThree.ma.. 2020. 1. 21.
Array().join(" ") & Object & Property & 객체의 property로 담겨있는 function이 method처럼 작동 & 'in' & 객체에 property를 더하고 빼는법 & class.prototype.method() describe("Object에 관해서", function() { describe("Property에 관해서", function() { let meglomaniac; beforeEach(function() { meglomaniac = { mastermind: "Joker", henchwoman: "Harley" }; }); it("객체에 property가 존재하는지 확인합니다.", function() { expect(meglomaniac.mastermind).toBe("Joker"); }); it("객체의 property는 알파벳 대소문자를 구분합니다.", function() { expect(meglomaniac.henchwoman).toBe("Harley"); expect(meglomaniac.henc.. 2020. 1. 21.