* let root1 = new Tree(1);
* let branch2 = root1.addChild(2);
* let branch3 = root1.addChild(3);
* let leaf4 = branch2.addChild(4);
* let leaf5 = branch2.addChild(5);
* let leaf6 = branch3.addChild(6);
* let leaf7 = branch3.addChild(7);
* let newTree = root1.map(function (value) {
* return value * 2;
* })
* newTree.value // 2
* newTree.children[0].value // 4
* newTree.children[1].value // 6
* newTree.children[0].children[1].value // 10
* newTree.children[1].children[1].value // 14
* root1.value // still 1
*/
const Tree = function (value) {
this.value = value;
this.children = [];
};
Tree.prototype.addChild = function(child) {
// your code here
let childNode = new Tree(child);
this.children.push(childNode);
};
Tree.prototype.map = function(callback) {
let mapTree = new Tree(callback(this.value));
if(this.children.length !== 0){
for(let i=0; i<this.children.length; i++){
mapTree.children[i] = this.children[i].map(callback);
}
}
return mapTree;
};
이해못하겠다.
심지어 딴 사람들의 질문을 보고 이해할려고 해도 이건 답이없다.
농담없이 500시간은 이 문제만 쳐다 봤다.
GG
한 10년뒤에 다시 보도록한다.
잘 가라 ㅃㅃ2