Skip to content

Instantly share code, notes, and snippets.

@viniciusarre
Last active September 23, 2017 22:29
Show Gist options
  • Select an option

  • Save viniciusarre/cf9e25c0f330aad75b1abc4674d1ea1d to your computer and use it in GitHub Desktop.

Select an option

Save viniciusarre/cf9e25c0f330aad75b1abc4674d1ea1d to your computer and use it in GitHub Desktop.
Object Cloner
/*Write a function called deepClone which takes an object and creates a copy of it. e.g.
{name: "Paddy", address: {town: "Lerum", country: "Sweden"}} -> {name: "Paddy", address: {town: "Lerum", country: "Sweden"}}*/
function deepClone(obj){
var obj2 = obj;
return obj2;
}
var Paddy = {name: "Paddy", address: {town: "Lerum", country: "Sweden"}};
console.log("Original: ",Paddy);
var Clone = deepClone(Paddy);
console.log("Clone: ",Clone);
{
"name": "object-cloner",
"version": "1.0.0",
"lockfileVersion": 1
}
{
"name": "object-cloner",
"version": "1.0.0",
"description": "This is the first challenge for the Spidergap Software Developer role.",
"main": "index.js",
"engine": "node 6.11.3",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start":"node index.js"
},
"author": "Vinícius Arré",
"license": "ISC"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment