Bonfire Record Collection Done

pull/18182/head
SaintPeter 2015-12-24 16:32:29 -08:00
parent 0ccfed6015
commit 9668246c87
1 changed files with 54 additions and 8 deletions

View File

@ -928,7 +928,7 @@
"description": [
"Quotes are not the only characters that can be <dfn>escaped</dfn> inside a string. Here is a table of common escape sequences:",
"<table class=\"table table-striped\"><thead><tr><th>Code</th><th>Output</th></tr></thead><tbody><tr><td>\\'</td><td>single quote</td></tr><tr><td>\\\"</td><td>double quote</td></tr><tr><td>\\\\</td><td>backslash</td></tr><tr><td>\\n</td><td>new line</td></tr><tr><td>\\r</td><td>carriage return</td></tr><tr><td>\\t</td><td>tab</td></tr><tr><td>\\b</td><td>backspace</td></tr><tr><td>\\f</td><td>form feed</td></tr></tbody></table>",
"<em>Note that the backslash itself must be escaped in order to display as a backslash.</em>",
"<emphasis>Note that the backslash itself must be escaped in order to display as a backslash.</emphasis>",
"<h4>Instructions</h4>",
"Encode the following sequence, separated by spaces:<br><code>backslash tab tab carriage-return new-line</code> and assign it to <code>myStr</code>"
],
@ -4167,14 +4167,17 @@
"You are given a JSON object representing (a small part of) your record collection. Each album is identified by a unqiue id number and which has several properties. Not all albums have complete information.",
"Write a function which takes an <code>id</code>, a property (<code>prop</code>), and a <code>value</code>.",
"For the given <code>id</code> in <code>collection</code>:",
"If the <code>property</code> is <code>\"tracks\"</code>, push the <code>value</code> onto the end of the <code>tracks</code> array.",
"If <code>value</code> is non-blank (<code>value !== \"\"</code>), then update or set the <code>value</code> for the <code>prop</code>.",
"If the <code>prop</code> is <code>\"tracks\"</code> and <code>value</code> is non-blank, push the <code>value</code> onto the end of the <code>tracks</code> array.",
"If <code>value</code> is blank, delete that <code>prop</code>.",
"Always return the entire collection object."
],
"releasedOn": "11/27/2015",
"tests": [
"assert(1===1, 'message: message here');"
"collection = collectionCopy; assert(update(5439, \"artist\", \"ABBA\")[5439][\"artist\"] === \"ABBA\", 'message: After <code>update(5439, \"artist\", \"ABBA\")</code>, <code>artist</code> should be <code>\"ABBA\"</code>');",
"update(2548, \"artist\", \"\"); assert(!collection[2548].hasOwnProperty(\"artist\"), 'message: After <code>update(2548, \"artist\", \"\")</code>, <code>artist</code> should not be set');",
"assert(update(1245, \"tracks\", \"Addicted to Love\")[1245][\"tracks\"].length === 1, 'message: After <code>update(1245, \"tracks\", \"Addicted to Love\")</code>, <code>tracks</code> should have a length of <code>1</code>');",
"update(2548, \"tracks\", \"\"); assert(!collection[2548].hasOwnProperty(\"tracks\"), 'message: After <code>update(2548, \"tracks\", \"\")</code>, <code>tracks</code> should not be set');"
],
"challengeSeed": [
"var collection = {",
@ -4202,6 +4205,8 @@
" album: \"ABBA Gold\"",
" }",
"};",
"// Keep a copy of the collection for tests",
"var collectionCopy = JSON.parse(JSON.stringify(collection));",
"",
"// Only change code below this line",
"function update(id, prop, value) {",
@ -4215,13 +4220,54 @@
""
],
"tail": [
""
"(function(x) { return \"collection = \\n\" + JSON.stringify(x, '\\n', 2); })(collection);"
],
"solutions": [
""
"var collection = {",
" 2548: {",
" album: \"Slippery When Wet\",",
" artist: \"Bon Jovi\",",
" tracks: [ ",
" \"Let It Rock\", ",
" \"You Give Love a Bad Name\" ",
" ]",
" },",
" 2468: {",
" album: \"1999\",",
" artist: \"Prince\",",
" tracks: [ ",
" \"1999\", ",
" \"Little Red Corvette\" ",
" ]",
" },",
" 1245: {",
" artist: \"Robert Palmer\",",
" tracks: [ ]",
" },",
" 5439: {",
" album: \"ABBA Gold\"",
" }",
"};",
"// Keep a copy of the collection for tests",
"var collectionCopy = JSON.parse(JSON.stringify(collection));",
"",
"// Only change code below this line",
"function update(id, prop, value) {",
" if(value !== \"\") {",
" if(prop === \"tracks\") {",
" collection[id][prop].push(value);",
" } else {",
" collection[id][prop] = value;",
" }",
" } else {",
" delete collection[id][prop];",
" }",
"",
" return collection;",
"}"
],
"type": "waypoint",
"challengeType": "1",
"type": "bonfire",
"challengeType": "5",
"nameCn": "",
"nameFr": "",
"nameRu": "",
@ -5446,4 +5492,4 @@
"challengeType": "0"
}
]
}
}