diff --git a/challenges/00-getting-started/getting-started.json b/challenges/00-getting-started/getting-started.json index f7c5e87a74..a3a162e309 100644 --- a/challenges/00-getting-started/getting-started.json +++ b/challenges/00-getting-started/getting-started.json @@ -81,7 +81,13 @@ "" ] ], - "challengeSeed": [], + "challengeSeed": [ + "function sym(args) {", + " return args;", + "}", + "", + "sym([1, 2, 3], [5, 2, 1, 4]);" + ], "tests": [], "type": "Waypoint", "challengeType": 7, diff --git a/challenges/08-coding-interview-questions-and-take-home-assignments/javascript-multiple-choice-questions.json b/challenges/08-coding-interview-questions-and-take-home-assignments/javascript-multiple-choice-questions.json new file mode 100644 index 0000000000..5baca9cd39 --- /dev/null +++ b/challenges/08-coding-interview-questions-and-take-home-assignments/javascript-multiple-choice-questions.json @@ -0,0 +1,112 @@ +{ + "name": "JavaScript Multiple Choice Questions", + "order": 8, + "time": "", + "helpRoom": "HelpJavaScript", + "challenges": [ + { + "id": "59874fc749228906236a3275", + "title": "Array.prototype.map", + "description": [ + { + "subtitle": "Flooring an Array", + "question": "What will the following code print out?\n
const results = [1.32, 2.43, 3.9]\n  .map(Math.floor);\nconsole.log(results);
", + "choices": [ + "
1.32 2.43 3.9
", + "
['1.32', '2.43', '3.9']
", + "
[1, 2, 3]
", + "
'1 2 3'
" + ], + "answer": 2, + "explanation": "The map function takes a callback function as it's first parameter and applies that function against every value inside the array. In this example, our callback function is the Math.floor function which will truncate the decimal points of all the numbers and convert them to integers." + }, + { + "subtitle": "Custom Map Functions", + "question": "What will the following code print out?\n
const results = ['a', 'b', 'c']\n  .map(a => [a.toUpperCase()]);\nconsole.log(results);
", + "choices": [ + "
[['A'], ['B'], ['C']]
", + "
['A', 'B', 'C']
", + "
['a', 'b', 'c]
", + "
'ABC'
" + ], + "answer": 0, + "explanation": "The map function will return a new array with each element equal to the old element ran through a callback function. Our callback function takes our original element, changes it to a upper case, and then wraps it in an array; thus, leaving us with [['A', 'B', 'C']]" + }, + { + "subtitle": "Maps on Maps", + "question": "What will the following code print out?\n
const results = [[4, 1], [2, 0], [3, 3]]\n  .map(a => \n    a.map(b => b % 2)[0] + a.map(b => b - 1)[1]\n  )\nconsole.log(results);
", + "choices": [ + "
[[0, 1], [0, 0], [1, 1]]
", + "
[[0, 0], [0, -1], [1, 2]]
", + "
[1, 1, 2]
", + "
[0, -1, 3]
" + ], + "answer": 3, + "explanation": "This answer can be explained by first looking at the example of what happens with the first element in our array, [4, 1]. Our first map callback will run a mod 2 map function over [4, 1] leaving us with a new array of [0, 1]. The second map call which is inside our callback will subtract 1 from every element, leaving us with [3, 0]. Last, we take element at index 0, 0, and add it to element of index 1 from our second map function, 0, leaving us with 0; thus, after the first iteration of the top level map function, we are left with an array that looks like so: [1, [2, 0], [3, 3]]. We simply keep doing that logic for the other elements until we finish: [1, -1, [3, 3]], and [1, -1, 3]" + }, + { + "subtitle": "Words Containing 'a'", + "question": "What will the following code print out?\n
const results = ['apple', 'dog', 'cat']\n  .map((a, i) => \n    a.indexOf('a') !== -1 ? i : null)\nconsole.log(results);
", + "choices": [ + "
[0, -1, 1]
", + "
[0, null, 2]
", + "
[null, null, null]
", + "
[-1, null, 2]
" + ], + "answer": 1, + "explanation": "This map example will return an array where each elements of the new array is either the original array index when the element contains the character 'a'; otherwise, an element of null for any words that do not have the character 'a'." + }, + { + "subtitle": "Accessing the Original Array Elements", + "question": "What will the following code print out?\n
const results = [1, 2, 3]\n  .map((a, _, o) => a + o[0])\nconsole.log(results);
", + "choices": [ + "
[1, 2, 3]
", + "
[0, 0, 0]
", + "
[3, 2, 1]
", + "
[2, 3, 4]
" + ], + "answer": 3, + "explanation": "This map example will add the value of the first element in the original array to all the other elements in the array." + }, + { + "subtitle": "More Map Hacking", + "question": "What will the following code print out?\n
const results = [8, 5, 3]\n  .map((a, i, o) => o[o.length - i - i])\nconsole.log(results);
", + "choices": [ + "
[3, 5, 8]
", + "
[5, 3, 8]
", + "
[8, 5, 3]
", + "
[3, 8, 5]
" + ], + "answer": 0, + "explanation": "This map example will reverse the array. The third argument to the map callback function is the original array; therefore, we can use the current index in the map function, and work our way backwards from the end of the array using the o.length." + }, + { + "subtitle": "Custom Scoping", + "question": "What will the following code print out?\n
const results = ['a', 'b', 'c']\n  .map(function(a) { return this[a]; }, {a: 9, b: 3, c: 1})\nconsole.log(results);
", + "choices": [ + "
['a', 'b', 'c']
", + "
[9, 3, 1]
", + "
[3, 9, 1]
", + "
[{a: 9}, {b: 3}, {c: 1}]
" + ], + "answer": 1, + "explanation": "This map example will reverse the array. The third argument to the map callback function is the original array; therefore, we can use the current index in the map function, and work our way backwards from the end of the array using the o.length." + }, + { + "subtitle": "Reversing in Map, Just Because", + "question": "What will the following code print out?\n
const results = [1, 2, 3, 4, 5]\n  .map((a, _, o) => o.reverse() && a)\nconsole.log(results);
", + "choices": [ + "
[5, 4, 3, 2, 1]
", + "
[5, 2, 3, 5, 1]
", + "
[1, 2, 3, 4, 5]
", + "
[1, 4, 3, 2, 5]
" + ], + "answer": 3, + "explanation": "This map example will reverse the array. The third argument to the map callback function is the original array; therefore, we can use the current index in the map function, and work our way backwards from the end of the array using the o.length." + } + ], + "tests": [], + "challengeType": 8 + } + ] +}