koans review

semin·2023년 4월 28일
1

section 1

목록 보기
11/11
post-thumbnail

오픈 북 시험이나 마찬가지인 koans
딱히 뭐... 문제 자체에서 크게 어렵지는 않지만
'Why does it work? '라는 생각을 전제로 깔고 풀어야 한다는 점
특별히 이해가 안 돼서 내일 한 번 더 봐야지! 싶은 건 없었다...

그래도 블로깅은 계속되어야 하니까!

페어분과 'why'를 고민한 코드 공유합니다.

function () {
  const obj = {
    mastermind: "Joker",
    henchwoman: "Harley",
    relations: ["Anarky", "Duela Dent", "Lucy"],
    twins: {
      "Jared Leto": "Suicide Squad",
      "Joaquin Phoenix": "Joker",
      "Heath Ledger": "The Dark Knight",
      "Jack Nicholson": "Tim Burton Batman",
    },
  };

  function passedByReference(refObj) {
    refObj.henchwoman = "Adam West";
  }
  passedByReference(obj);
  expect(obj.henchwoman).to.equal("Adam West");

  const assignedObj = obj;
  assignedObj["relations"] = [1, 2, 3];
  expect(obj["relations"]).to.deep.equal([1, 2, 3]);

  const copiedObj = Object.assign({}, obj);

  copiedObj.mastermind = "James Wood";
  expect(obj.mastermind).to.equal("Joker");
  obj.henchwoman = "Harley";
  expect(copiedObj.henchwoman).to.equal("Adam West");
  delete obj.twins["Jared Leto"];
  expect("Jared Leto" in copiedObj.twins).to.equal(false);
}

/*
function expect(testingValue).whatItTakes
    expect(isEven(3)).to.be.true => 'isEven(3)'의 결과값은 참(true)이어야 한다'
    expect(1 + 2).to.equal(3) => 'sum(1, 2)의 결과값은 3과 같아야(equal) 한다'
  
  'whatItTakes' function: matcher
  '참이어야 한다' => to.be.true
  '3과 같아야 한다' => to.equal(3)
*/

내가 이해한 걸 설명하는데 헷갈리길래
정리를 위해 휘갈겨본 필기도 공유합니다...
낯선이의 필체 구경하고 가세요

0개의 댓글

관련 채용 정보