From 5105efa62492b2e2d56c35e95c21fa871cb4e942 Mon Sep 17 00:00:00 2001 From: Quincy Larson Date: Wed, 21 Oct 2015 15:04:58 -0700 Subject: [PATCH] add solutions to challenges object and add solutions for upper intermediate bonfires --- common/models/challenge.json | 4 ++++ seed/challenges/upper-intermediate-bonfires.json | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/common/models/challenge.json b/common/models/challenge.json index 84cf3a4c6b..81d6af6eef 100644 --- a/common/models/challenge.json +++ b/common/models/challenge.json @@ -82,6 +82,10 @@ }, "descriptionPt": { "type": "array" + }, + "solutions": { + "type": "array", + "default": [] } }, "validations": [], diff --git a/seed/challenges/upper-intermediate-bonfires.json b/seed/challenges/upper-intermediate-bonfires.json index c09cb30da4..b4ab210cd2 100644 --- a/seed/challenges/upper-intermediate-bonfires.json +++ b/seed/challenges/upper-intermediate-bonfires.json @@ -39,6 +39,9 @@ "Closures", "Details of the Object Model" ], + "solutions": [ + "var Person = function(firstAndLast) {\n\n var firstName, lastName;\n\n function updateName(str) { \n firstName = str.split(\" \")[0];\n lastName = str.split(\" \")[1]; \n }\n\n updateName(firstAndLast);\n\n this.getFirstName = function(){\n return firstName;\n };\n \n this.getLastName = function(){\n return lastName;\n };\n \n this.getFullName = function(){\n return firstName + \" \" + lastName;\n };\n \n this.setFirstName = function(str){\n firstName = str;\n };\n \n\n this.setLastName = function(str){\n lastName = str;\n };\n \n this.setFullName = function(str){\n updateName(str);\n };\n};\n\nvar bob = new Person('Bob Ross');\nbob.getFullName();" + ], "type": "bonfire", "challengeType": 5, "nameCn": "", @@ -80,6 +83,9 @@ "MDNlinks": [ "Math.pow()" ], + "solutions": [ + "function orbitalPeriod(arr) {\n var GM = 398600.4418;\n var earthRadius = 6367.4447;\n var TAU = 2 * Math.PI; \n return arr.map(function(obj) {\n return {\n name: obj.name,\n orbitalPeriod: Math.round(TAU * Math.sqrt(Math.pow(obj.avgAlt+earthRadius, 3)/GM))\n };\n });\n}\n\norbitalPeriod([{name : \"sputkin\", avgAlt : 35873.5553}]);\n" + ], "type": "bonfire", "challengeType": 5, "nameCn": "", @@ -120,6 +126,9 @@ "Array.reduce()" ], "type": "bonfire", + "solutions": [ + "function pairwise(arr, arg) {\n var sum = 0;\n arr.forEach(function(e, i, a) {\n if (e != null) { \n var diff = arg-e;\n a[i] = null;\n var dix = a.indexOf(diff);\n if (dix !== -1) {\n sum += dix;\n sum += i;\n a[dix] = null;\n } \n }\n });\n return sum;\n}\n\npairwise([1,4,2,3,0,5], 7);\n" + ], "challengeType": 5, "nameCn": "", "descriptionCn": [],