Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions koans/01_Introduction.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ describe('expect에 대해서 학습합니다.', function () {
expect(true).to.be.true;
*/
// TODO: 테스트가 통과될 수 있도록(테스트하는 값이 true가 되도록) expect의 첫 번째 전달인자를 수정합니다.
expect(false).to.be.true;
expect(true).to.be.true;
});

it('테스트하는 값(expect의 전달인자)이 falsy 여부를 검사합니다.', function () {
// 반대의 경우에는 어떻게 해야할까요?
// TODO: 테스트가 통과될 수 있도록(테스트하는 값이 false가 되도록) expect의 첫 번째 전달인자를 수정합니다.
expect(true).to.be.false;
expect(false).to.be.false;
});

/*
Expand All @@ -53,7 +53,7 @@ describe('expect에 대해서 학습합니다.', function () {
it("'테스트하는 값'을 '기대하는 값'과 비교한 결과가 참 인지 확인합니다.", function () {
// '테스트하는 값'은 우리가 작성한 어떤 코드의 실제 실행 결과 값이므로 '실제 값'이라고 불러도 됩니다.
let actualValue = 1 + 1;
let expectedValue = FILL_ME_IN; // TODO: 'FILL_ME_IN'을 변경하여 테스트 케이스를 완성합니다.
let expectedValue = 2; // TODO: 'FILL_ME_IN'을 변경하여 테스트 케이스를 완성합니다.
expect(actualValue === expectedValue).to.be.true;
});

Expand All @@ -68,13 +68,13 @@ describe('expect에 대해서 학습합니다.', function () {
이후에도 같은 방식으로 'FILL_ME_IN' 변경하면 됩니다.
*/
it('Matcher .equal 의 사용법을 학습합니다.', function () {
let expectedValue = FILL_ME_IN; // TODO
let expectedValue = 2; // TODO
// .equal은 두 값이 타입까지 엄격하게 같은지 검사(strict equality, ===)합니다.
expect(1 + 1).to.equal(expectedValue);
});

it('Matcher .equal의 사용법을 학습합니다.', function () {
let actualValue = (1 + 1).toString();
expect(actualValue).to.equal(FILL_ME_IN); // TODO
expect(actualValue).to.equal('2'); // TODO
});
});
12 changes: 6 additions & 6 deletions koans/02_Types-part1.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
describe('type에 대해서 학습합니다.', function () {
it("비교연산자 '=='는 두 값의 일치 여부를 느슨하게 검사(loose equality)합니다.", function () {
let actualValue = 1 + 1;
let expectedValue = FILL_ME_IN;
let expectedValue = 2;
expect(actualValue == expectedValue).to.be.true;

/*
Expand Down Expand Up @@ -33,26 +33,26 @@ describe('type에 대해서 학습합니다.', function () {

it("비교연산자 '==='는 두 값의 일치 여부를 엄격하게 검사(strict equality)합니다.", function () {
let actualValue = 1 + 1;
let expectedValue = FILL_ME_IN;
let expectedValue = 2;
expect(actualValue === expectedValue).to.be.true;
// 이제 'FILL_ME_IN'을 대신할 수 있는 건 number 타입의 2뿐입니다.
// 문자열 '2'는 테스트를 통과하지 못합니다.
});

it('expect의 전달인자로 들어간 표현식의 평가(evaluation) 결과를 예측해 봅니다.', function () {
expect(1 + '1').to.equal(FILL_ME_IN);
expect(1 + '1').to.equal('11');
});

it('expect의 전달인자로 들어간 표현식의 평가(evaluation) 결과를 예측해 봅니다.', function () {
expect(123 - '1').to.equal(FILL_ME_IN);
expect(123 - '1').to.equal(122);
});

it('expect의 전달인자로 들어간 표현식의 평가(evaluation) 결과를 예측해 봅니다.', function () {
expect(1 + true).to.equal(FILL_ME_IN);
expect(1 + true).to.equal(2);
});

it('expect의 전달인자로 들어간 표현식의 평가(evaluation) 결과를 예측해 봅니다.', function () {
expect('1' + true).to.equal(FILL_ME_IN);
expect('1' + true).to.equal('1true');
});

/*
Expand Down
12 changes: 6 additions & 6 deletions koans/03_LetConst.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ describe("'const'에 대해서 학습합니다.", function () {
it("'const'로 선언된 변수에는 재할당(reassignment)이 금지됩니다.", function () {
// 아래 코드에서 문제가 되는 부분을 삭제합니다.
const constNum = 0;
constNum = 0;

expect(constNum).to.equal(0);

const constString = 'I am a const';
constString = "which means I'm a constant variable, delete me.";

expect(constString).to.equal('I am a const');
});

it("'const'로 선언된 배열의 경우 새로운 요소를 추가하거나 삭제할 수 있습니다.", function () {
const arr = [];
const toBePushed = FILL_ME_IN;
const toBePushed = 42;
arr.push(toBePushed);
expect(arr[0]).to.equal(42);

Expand All @@ -22,15 +22,15 @@ describe("'const'에 대해서 학습합니다.", function () {

it("'const'로 선언된 객체의 경우, 속성을 추가하거나 삭제할 수 있습니다.", function () {
const obj = { x: 1 };
expect(obj.x).to.equal(FILL_ME_IN);
expect(obj.x).to.equal(1);

delete obj.x;
expect(obj.x).to.equal(FILL_ME_IN);
expect(obj.x).to.equal(undefined);

// 여전히 재할당은 금지됩니다.
// obj = { x: 123 };

obj.occupation = FILL_ME_IN;
obj.occupation = 'SW Engineer';
expect(obj['occupation']).to.equal('SW Engineer');
});

Expand Down
44 changes: 22 additions & 22 deletions koans/04_Scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ describe('scope 대해서 학습합니다.', function () {
it('함수 선언식(declaration)과 함수 표현식(expression)의 차이를 확인합니다.', function () {
let funcExpressed = 'to be a function';

expect(typeof funcDeclared).to.equal(FILL_ME_IN);
expect(typeof funcExpressed).to.equal(FILL_ME_IN);
expect(typeof funcDeclared).to.equal('function');
expect(typeof funcExpressed).to.equal('string');

function funcDeclared() {
return 'this is a function declaration';
Expand All @@ -17,10 +17,10 @@ describe('scope 대해서 학습합니다.', function () {
// 자바스크립트 함수 호이스팅(hoisting)에 대해서 검색해 봅니다.

const funcContainer = { func: funcExpressed };
expect(funcContainer.func()).to.equal(FILL_ME_IN);
expect(funcContainer.func()).to.equal('this is a function expression');

funcContainer.func = funcDeclared;
expect(funcContainer.func()).to.equal(FILL_ME_IN);
expect(funcContainer.func()).to.equal('this is a function declaration');
});

it('lexical scope에 대해서 확인합니다.', function () {
Expand All @@ -44,29 +44,29 @@ describe('scope 대해서 학습합니다.', function () {
return message;
}

expect(getMessage()).to.equal(FILL_ME_IN);
expect(shadowGlobal()).to.equal(FILL_ME_IN);
expect(shadowGlobal2('Parameter')).to.equal(FILL_ME_IN);
expect(shadowParameter('Parameter')).to.equal(FILL_ME_IN);
expect(message).to.equal(FILL_ME_IN);
expect(getMessage()).to.equal('Outer');
expect(shadowGlobal()).to.equal('Inner');
expect(shadowGlobal2('Parameter')).to.equal('Parameter');
expect(shadowParameter('Parameter')).to.equal('Do not use parameters like this!');
expect(message).to.equal('Outer');
});

it('default parameter에 대해 확인합니다.', function () {
function defaultParameter(num = 5) {
return num;
}

expect(defaultParameter()).to.equal(FILL_ME_IN);
expect(defaultParameter(10)).to.equal(FILL_ME_IN);
expect(defaultParameter()).to.equal(5);
expect(defaultParameter(10)).to.equal(10);

function pushNum(num, arr = []) {
arr.push(num);
return arr;
}

expect(pushNum(10)).to.deep.equal(FILL_ME_IN);
expect(pushNum(20)).to.deep.equal(FILL_ME_IN);
expect(pushNum(4, [1, 2, 3])).to.deep.equal(FILL_ME_IN);
expect(pushNum(10)).to.deep.equal([10]);
expect(pushNum(20)).to.deep.equal([20]);
expect(pushNum(4, [1, 2, 3])).to.deep.equal([1, 2, 3, 4]);
});

it('클로저(closure)에 대해 확인합니다.', function () {
Expand All @@ -79,9 +79,9 @@ describe('scope 대해서 학습합니다.', function () {
const increaseBy3 = increaseBy(3);
const increaseBy5 = increaseBy(5);

expect(increaseBy3(10)).to.equal(FILL_ME_IN);
expect(increaseBy5(10)).to.equal(FILL_ME_IN);
expect(increaseBy(8)(6) + increaseBy(5)(9)).to.equal(FILL_ME_IN);
expect(increaseBy3(10)).to.equal(13);
expect(increaseBy5(10)).to.equal(15);
expect(increaseBy(8)(6) + increaseBy(5)(9)).to.equal(28);

/*
mdn에 따르면 클로저의 정의는 다음과 같습니다. 반드시 기억하시기 바랍니다.
Expand Down Expand Up @@ -121,16 +121,16 @@ describe('scope 대해서 학습합니다.', function () {

innerFn();

expect(age).to.equal(FILL_ME_IN);
expect(name).to.equal(FILL_ME_IN);
expect(age).to.equal(26);
expect(name).to.equal('jimin');

return innerFn;
}

const innerFn = outerFn();

expect(age).to.equal(FILL_ME_IN);
expect(name).to.equal(FILL_ME_IN);
expect(innerFn()).to.equal(FILL_ME_IN);
expect(age).to.equal(27);
expect(name).to.equal('jimin');
expect(innerFn()).to.equal(178);
});
});
20 changes: 10 additions & 10 deletions koans/05_ArrowFunction.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@ describe('화살표 함수에 관해서', function () {
return x + y
}

expect(add(5, 8)).to.eql(FILL_ME_IN)
expect(add(5, 8)).to.eql(13)
})

it('화살표 함수 사용법을 익힙니다', function () {
// function 키워드를 생략하고 화살표 => 를 붙입니다
const add = (x, y) => {
return x + y
}
expect(add(10, 20)).to.eql(FILL_ME_IN)
expect(add(10, 20)).to.eql(30)

// 리턴을 생략할 수 있습니다
const subtract = (x, y) => x - y
expect(subtract(10, 20)).to.eql(FILL_ME_IN)
expect(subtract(10, 20)).to.eql(-10)

// 필요에 따라 소괄호를 붙일 수도 있습니다
const multiply = (x, y) => (x * y)
expect(multiply(10, 20)).to.eql(FILL_ME_IN)
expect(multiply(10, 20)).to.eql(200)

// 파라미터가 하나일 경우 소괄호 생략이 가능합니다
const divideBy10 = x => x / 10
expect(divideBy10(100)).to.eql(FILL_ME_IN)
expect(divideBy10(100)).to.eql(10)
})

it('화살표 함수를 이용해 클로저를 표현합니다', function () {
Expand All @@ -34,19 +34,19 @@ describe('화살표 함수에 관해서', function () {
}
}

expect(adder(50)(10)).to.eql(FILL_ME_IN)
expect(adder(50)(10)).to.eql(60)

const subtractor = x => y => {
return x - y
}

expect(subtractor(50)(10)).to.eql(FILL_ME_IN)
expect(subtractor(50)(10)).to.eql(40)

const htmlMaker = tag => textContent => `<${tag}>${textContent}</${tag}>`
expect(htmlMaker('div')('javascript')).to.eql(FILL_ME_IN)
expect(htmlMaker('div')('javascript')).to.eql('<div>javascript</div>')

const liMaker = htmlMaker('li')
expect(liMaker('1st item')).to.eql(FILL_ME_IN)
expect(liMaker('2nd item')).to.eql(FILL_ME_IN)
expect(liMaker('1st item')).to.eql('<li>1st item</li>')
expect(liMaker('2nd item')).to.eql('<li>2nd item</li>')
})
})
44 changes: 22 additions & 22 deletions koans/06_Types-part2.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ describe('primitive data type과 reference data type에 대해서 학습합니
*/
it('원시 자료형은 값 자체에 대한 변경이 불가능(immutable)합니다.', function () {
let name = 'javascript';
expect(name).to.equal(FILL_ME_IN);
expect(name.toUpperCase()).to.equal(FILL_ME_IN);
expect(name).to.equal(FILL_ME_IN);
expect(name).to.equal('javascript');
expect(name.toUpperCase()).to.equal('JAVASCRIPT');
expect(name).to.equal('javascript');
// 새로운 값으로 재할당은 가능합니다.
name = name.toUpperCase();
expect(name).to.equal(FILL_ME_IN);
expect(name).to.equal('JAVASCRIPT');

/*
원시 자료형은 값 자체에 대한 변경이 불가능하다고 하는데, 한 변수에 다른 값을 할당하는 것은 변경이 된 것이 아닌가요?
Expand All @@ -29,14 +29,14 @@ describe('primitive data type과 reference data type에 대해서 학습합니
let allowedToDrink = overTwenty;

overTwenty = false;
expect(overTwenty).to.equal(FILL_ME_IN);
expect(allowedToDrink).to.equal(FILL_ME_IN);
expect(overTwenty).to.equal(false);
expect(allowedToDrink).to.equal(true);

let variable = 'variable';
let variableCopy = 'variableCopy';
variableCopy = variable;
variable = variableCopy;
expect(variable).to.equal(FILL_ME_IN);
expect(variable).to.equal('variable');
});

it('원시 자료형 또는 원시 자료형의 데이터를 함수의 전달인자로 전달할 경우, 값 자체의 복사가 일어납니다.', function () {
Expand All @@ -45,14 +45,14 @@ describe('primitive data type과 reference data type에 대해서 학습합니
year = year + 10;
}
afterTenYears(currentYear);
expect(currentYear).to.equal(FILL_ME_IN);
expect(currentYear).to.equal(2020);
function afterTenYears2(currentYear) {
currentYear = currentYear + 10;
return currentYear;
}
let after10 = afterTenYears2(currentYear);
expect(currentYear).to.equal(FILL_ME_IN);
expect(after10).to.equal(FILL_ME_IN);
expect(currentYear).to.equal(2020);
expect(after10).to.equal(2030);
// 사실 함수의 전달인자도 변수에 자료(data)를 할당하는 것입니다.
// 함수를 호출하면서 넘긴 전달인자가 호출된 함수의 지역변수로 (매 호출 시마다) 새롭게 선언됩니다.
});
Expand Down Expand Up @@ -106,20 +106,20 @@ describe('primitive data type과 reference data type에 대해서 학습합니
*/
it('참조 자료형의 데이터는 동적(dynamic)으로 변합니다.', function () {
const arr = [1, 2, 3];
expect(arr.length).to.equal(FILL_ME_IN);
expect(arr.length).to.equal(3);
arr.push(4, 5, 6);
expect(arr.length).to.equal(FILL_ME_IN);
expect(arr.length).to.equal(6);
arr.pop();
expect(arr.length).to.equal(FILL_ME_IN);
expect(arr.length).to.equal(5);

const obj = {};
expect(Object.keys(obj).length).to.equal(FILL_ME_IN);
expect(Object.keys(obj).length).to.equal(0);
obj['name'] = 'codestates';
obj.quality = 'best';
obj.product = ['sw engineering', 'product manager', 'growth marketing', 'data science'];
expect(Object.keys(obj).length).to.equal(FILL_ME_IN);
expect(Object.keys(obj).length).to.equal(3);
delete obj.name;
expect(Object.keys(obj).length).to.equal(FILL_ME_IN);
expect(Object.keys(obj).length).to.equal(2);
});

it('참조 자료형을 변수에 할당할 경우, 데이터의 주소가 저장됩니다.', function () {
Expand All @@ -135,19 +135,19 @@ describe('primitive data type과 reference data type에 대해서 학습합니
let allowedToDrink = overTwenty;

overTwenty.push('san');
expect(allowedToDrink).to.deep.equal(FILL_ME_IN);
expect(allowedToDrink).to.deep.equal(['hongsik', 'minchul', 'hoyong', 'san']);
overTwenty[1] = 'chanyoung';
expect(allowedToDrink[1]).to.deep.equal(FILL_ME_IN);
expect(allowedToDrink[1]).to.deep.equal('chanyoung');
// .deep.equal은 배열의 요소나 객체의 속성이 서로 같은지 확인하는 matcher입니다.
// .equal아닌 .deep.equal을 사용하는 이유는 아래 테스트 코드를 통해 고민하시기 바랍니다.

const ages = [22, 23, 27];
allowedToDrink = ages;
expect(allowedToDrink === ages).to.equal(FILL_ME_IN);
expect(allowedToDrink === ages).to.equal(true);

const nums1 = [1, 2, 3];
const nums2 = [1, 2, 3];
expect(nums1 === nums2).to.equal(FILL_ME_IN);
expect(nums1 === nums2).to.equal(false);

const person = {
son: {
Expand All @@ -157,8 +157,8 @@ describe('primitive data type과 reference data type에 대해서 학습합니

const boy = person.son;
boy.age = 20;
expect(person.son.age).to.equal(FILL_ME_IN);
expect(person.son === boy).to.equal(FILL_ME_IN);
expect(person.son.age).to.equal(20);
expect(person.son === boy).to.equal(true);

/*
아래의 테스트 코드들은 선뜻 받아들이기 힘들 수 있습니다.
Expand Down
Loading