IM Basic HA(12.16 ~12.17)

JEHYUN KIM
4 min readDec 17, 2020

It was the first HA since we started this immersive course.
There were some multiple questions using google form. It was tricky but thanks to this I could check my understanding of the definitions and usage of the methods.
After that, I had to solve the questions using vscode and 6 js files were waiting to be solved. (Algo-complexity, ds-queue, js-inheritance-pseudoclassical-alt, recursion-print-array, this-keyword and the tree-map)
Out of all the ‘tree-map’ had the highest difficulty. I had a hard time understanding how to solve it(especially the callback part) and now I feel much better thanks to my classmates who helped me to understand the basics of it.
For some reason today I am struggling with a terrible headache which makes me lose all the motivation to study and I hope it will get better tomorrow.
My plan for the rest of the week is to revise the things that I learnt from the start. It is kinda annoying but I know that this is very important and if I procrastinate, things will get worse. Now or never.

Below is the reference code.

var Tree = function(value) {this.value = value;
this.children = [];
};
/*
* add an immediate child
* (wrap values in Tree nodes if they're not already wrapped)
*/
Tree.prototype.addChild = function(child) {if (!child || !(child instanceof Tree)) {child = new Tree(child);}this.children.push(child);// return the tree for convenience
return this;
};
Tree.prototype.map = function(callback) {return this.children.reduce(function(tree, child) {return tree.addChild(child.map(callback));}, new Tree(callback(this.value)));};module.exports = Tree;

(Callback Function)콜백함수
자바스크립트는 함수를 변수로 저장(함수 표현식)할 수 있음.
그렇기 때문에 함수 표현식에 의한 변수를
함수의 인수로 사용하여 매개변수에 전달할 수 있다.
이때 함수의 매개변수에 전달되는 함수 표현식의 변수인 인수를 콜백 함수라고 한다.

--

--