importPackage(java.io);
importPackage(java.lang);
// your code goes here
var arr = [{name:"adam",age:"21"},
{name:"freddie",age:"35",children:[{name:"mercury",age:"25"}]},
{name:"jim",age:"35",children:[{name:"morrison",age:"25"}]}
];
var res = new Array([]);
var cp = [];
var deepCopy = function (tree) {
var copied = {};
var res = [];
for (var i = 0; i < tree.length; i++) {
System.out.println(tree[i].name);
if (tree[i].children) {
System.out.println("hello");
var temps = new Object({});
var temp1 = new Array([]);
temps.name =tree[i].name;
temps.age = tree[i].age;
temp1 = deepCopy(tree[i].children);
temps.children = temp1;
res.push(temps);
temps = new Object({});
// System.out.println("child" + temp1.name);
// temp1 = new Array([]);
}
else {
var temp = new Object({});
temp.name = tree[i].name;
temp.age = tree[i].age;
// System.out.println("ello");
res.push(temp);
System.out.println("lo");
}
//System.out.println("llo");
}
return res;
}
res = deepCopy(arr);
for (var i = 0; i < arr.length; i++) {
System.out.print(arr[i].name + " ");
}
System.out.println();
//arr[0].name = "sahu";
//arr[1].children.name = "ss";
for (var i = 0; i < arr.length; i++) {
System.out.print(arr[i].name + " ");
}
//System.out.println(arr[1].children.name);
for (var i = 0; i < res.length; i++) {
System.out.print(res[i].name + " ");
}
System.out.println(res[1].children.name);