{"ScriptPreparationCode":"var map2 = new Map();\r\n\r\nmap2.set(\u0027cat\u0027, \u0027Kitten\u0027);\r\nmap2.set(\u0027cattle\u0027, \u0027Calf\u0027);\r\nmap2.set(\u0027cheetah\u0027, \u0027Cub\u0027);\r\nmap2.set(\u0027dog\u0027, \u0027Pup\u0027);\r\n\r\nvar babyAnimal2 = {\r\n cat: \u0027Kitten\u0027,\r\n cattle: \u0027Calf\u0027,\r\n cheetah: \u0027Cub\u0027,\r\n dog: \u0027Pup\u0027\r\n}","TestCases":[{"Name":"Switch","Code":"var animal = [\u0022dog\u0022, \u0022cat\u0022, \u0022cattle\u0022, \u0022cheetah\u0022][Math.floor(Math.random() * 4)]\r\n\r\nfunction test(animal) {\r\n switch(animal){\r\n case \u0027cat\u0027: return \u0027Kitten\u0027\r\n case \u0027cattle\u0027: return \u0027Calf\u0027\r\n case \u0027cheetah\u0027: return \u0027Cub\u0027\r\n case \u0027dog\u0027: return \u0027Pup\u0027\r\n default: return \u0022I don\u0027t know that\u0022\r\n }\r\n}\r\n\r\nconsole.log(test(animal))","IsDeferred":false},{"Name":"Object Literal","Code":"var animal = [\u0022dog\u0022, \u0022cat\u0022, \u0022cattle\u0022, \u0022cheetah\u0022][Math.floor(Math.random() * 4)]\r\n\r\nfunction test(animal) {\r\n var babyAnimal = {\r\n cat:\u0027Kitten\u0027,\r\n cattle:\u0027Calf\u0027,\r\n cheetah:\u0027Cub\u0027,\r\n dog:\u0027Pup\u0027\r\n }\r\n\r\n return babyAnimal[animal] ?? \u0022I don\u0027t know that\u0022\r\n}\r\n\r\nconsole.log(test(animal))","IsDeferred":false},{"Name":"If Else","Code":"var animal = [\u0022dog\u0022, \u0022cat\u0022, \u0022cattle\u0022, \u0022cheetah\u0022][Math.floor(Math.random() * 4)]\r\n\r\nfunction test(animal) {\r\n if(animal===\u0027cat\u0027){\r\n return \u0027Kitten\u0027\r\n} else if(animal==\u0027cattle\u0027){\r\n return \u0027Calf\u0027\r\n} else if(animal===\u0027cheetah\u0027){\r\n return \u0027Cub\u0027;\r\n} else if(animal===\u0027dog\u0027){\r\n return \u0027Pup\u0027;\r\n}\r\n return \u0022I don\u0027t know that\u0022\r\n}\r\n\r\nconsole.log(test(animal))","IsDeferred":false},{"Name":"Object Literal defined outside function","Code":"var animal = [\u0022dog\u0022, \u0022cat\u0022, \u0022cattle\u0022, \u0022cheetah\u0022][Math.floor(Math.random() * 4)]\r\n\r\nfunction test(animal) {\r\nreturn babyAnimal2[animal] ?? \u0022I don\u0027t know that\u0022\r\n}\r\n\r\nconsole.log(test(animal))","IsDeferred":false},{"Name":"Map","Code":"var animal = [\u0022dog\u0022, \u0022cat\u0022, \u0022cattle\u0022, \u0022cheetah\u0022][Math.floor(Math.random() * 4)]\r\n\r\nfunction test(animal) {\r\n const map1 = new Map();\r\n\r\n map1.set(\u0027cat\u0027, \u0027Kitten\u0027);\r\n map1.set(\u0027cattle\u0027, \u0027Calf\u0027);\r\n map1.set(\u0027cheetah\u0027, \u0027Cub\u0027);\r\n map1.set(\u0027dog\u0027, \u0027Pup\u0027);\r\n\r\n return map1.get(animal) || \u0022I don\u0027t know that\u0022\r\n}\r\n\r\nconsole.log(test(animal))","IsDeferred":false},{"Name":"Map - defined outsid function","Code":"var animal = [\u0022dog\u0022, \u0022cat\u0022, \u0022cattle\u0022, \u0022cheetah\u0022][Math.floor(Math.random() * 4)]\r\n\r\nfunction test(animal) {\r\n return map2.get(animal) || \u0022I don\u0027t know that\u0022\r\n}\r\n\r\nconsole.log(test(animal))","IsDeferred":false}]}