Created
April 18, 2017 07:28
Revisions
-
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,39 @@ var dolly = ["Dolly", "sheep", []]; var dollyClone = cloneAnimal(dolly); var dollyClone2 = cloneAnimal(dolly); var dollyClone3 = cloneAnimal(dolly); // The clone is of same species, with new name and no offspring console.log(dollyClone) console.log(dollyClone2)// ["DollyClone", "sheep", []] console.log(dollyClone3) // The parent animal now has an offspring in its array console.log(dolly) // ["Dolly", "sheep", ["DollyClone"]] function cloneAnimal(parentAnimal){ var numOffspring=parentAnimal[2].length; var cloneAnimal=parentAnimal.slice(0,2); cloneAnimal[0]=parentAnimal.slice(0,1)+"Clone"+(numOffspring+1); cloneAnimal.push([]); parentAnimal[2].push(cloneAnimal[0]); return cloneAnimal; } /* SCHOOL SOLUTION function cloneAnimal(animal) { var cloneName = animal[0] + "Clone"; var clone = [cloneName, animal[1], []]; animal[2].push(cloneName); return clone; } */