let dfs = (node) => {

}

let Node = (value) => {
	this.value = value;
	this.children = [];
}

Node.prototype.addChild = (child) => {
	this.children.push(child);
	return child;
}
let root = new Node(1);
let rootChild1 = root.addChild(new Node(2));
let rootChild2 = root.addChild(new Node(3));
let leaf1 = rootChild1.addChild(new Node(4));
let leaf2 = rootChild1.addChild(new Node(5));

let dfs = (node) => {
	// 최종적으로 출력해줄 배열 변수가 필요하다.
	let result = [];

	// 자식노드가 있는지 확인하기 위해서 재귀적으로 돌려줘야한다. 
	let checkNode = (node) => {
		// node.children 있는지 확인한다.
		if(node.children) {
			// 값이 있으면 node.value를 result 배열에 넣어준다.
			result.push(node.value);

			// 자식이 있으니까 for문으로 node.children의 길이만큼 탐색해서 재귀적으로 돌려줘야한다.
			for(let i=0; i<node.children.length; i++) {
				// i번째 요소를 재귀적으로 계속 보낸다.
				checkNode(node.children[i]);
			}
		} else {
				// node.children이 없는 경우에도 그냥 result에 node.value를 넣어준다.
				result.push(node.value);
			} 
	}
	// checkNode를 호출해준다.
	checkNode(node);
	// 최종 result 변수를 리턴한다.
	return result;
}

let Node = (value) => {
	this.value = value;
	this.children = [];
}

Node.prototype.addChild = (child) => {
	this.children.push(child);
	return child;
}
let dfs = (node) => {
	// 최종적으로 출력해줄 배열 변수가 필요하다.
	let result = [node.value];

	// node.children 탐색
	node.children.forEach(el => {
		result = result.concat(dfs(el));
	});

	// 최종 result 변수를 리턴한다.
	return result;
}

let Node = (value) => {
	this.value = value;
	this.children = [];
}

Node.prototype.addChild = (child) => {
	this.children.push(child);
	return child;
}