fix/record-collection (#36002)
* fix/record-collection * fix/remove-old-assert-messages * fix/attempt-to-fix-build-error * fix/attempt-to-fix-build-error * fix/change-verbiage-and-tidy-up * fix/remove-brackets-in-regex
This commit is contained in:
@ -30,20 +30,22 @@ You may refer back to <a href="learn/javascript-algorithms-and-data-structures/b
|
|||||||
|
|
||||||
```yml
|
```yml
|
||||||
tests:
|
tests:
|
||||||
|
- text: You should not change the <code>collection</code> object's initialization
|
||||||
|
testString: 'assert(code.match(/var collection = {\s*2548: {\s*album: "Slippery When Wet",\s*artist: "Bon Jovi",\s*tracks: \[\s*"Let It Rock",\s*"You Give Love a Bad Name"\s*\]\s*},\s*2468: {\s*album: "1999",\s*artist: "Prince",\s*tracks: \[\s*"1999",\s*"Little Red Corvette"\s*\]\s*},\s*1245: {\s*artist: "Robert Palmer",\s*tracks: \[ \]\s*},\s*5439: {\s*album: "ABBA Gold"\s*}\s*};/g));'
|
||||||
- text: After <code>updateRecords(5439, "artist", "ABBA")</code>, <code>artist</code> should be <code>"ABBA"</code>
|
- text: After <code>updateRecords(5439, "artist", "ABBA")</code>, <code>artist</code> should be <code>"ABBA"</code>
|
||||||
testString: collection = collectionCopy; assert(updateRecords(5439, "artist", "ABBA")[5439]["artist"] === "ABBA", 'After <code>updateRecords(5439, "artist", "ABBA")</code>, <code>artist</code> should be <code>"ABBA"</code>');
|
testString: assert(updateRecords(5439, "artist", "ABBA")[5439]["artist"] === "ABBA");
|
||||||
- text: After <code>updateRecords(5439, "tracks", "Take a Chance on Me")</code>, <code>tracks</code> should have <code>"Take a Chance on Me"</code> as the last element.
|
- text: After <code>updateRecords(5439, "tracks", "Take a Chance on Me")</code>, <code>tracks</code> should have <code>"Take a Chance on Me"</code> as the last element.
|
||||||
testString: assert(updateRecords(5439, "tracks", "Take a Chance on Me")[5439]["tracks"].pop() === "Take a Chance on Me", 'After <code>updateRecords(5439, "tracks", "Take a Chance on Me")</code>, <code>tracks</code> should have <code>"Take a Chance on Me"</code> as the last element.');
|
testString: assert(updateRecords(5439, "tracks", "Take a Chance on Me")[5439]["tracks"].pop() === "Take a Chance on Me");
|
||||||
- text: After <code>updateRecords(2548, "artist", "")</code>, <code>artist</code> should not be set
|
- text: After <code>updateRecords(2548, "artist", "")</code>, <code>artist</code> should not be set
|
||||||
testString: updateRecords(2548, "artist", ""); assert(!collection[2548].hasOwnProperty("artist"), 'After <code>updateRecords(2548, "artist", "")</code>, <code>artist</code> should not be set');
|
testString: updateRecords(2548, "artist", ""); assert(!collection[2548].hasOwnProperty("artist"));
|
||||||
- text: After <code>updateRecords(1245, "tracks", "Addicted to Love")</code>, <code>tracks</code> should have <code>"Addicted to Love"</code> as the last element.
|
- text: After <code>updateRecords(1245, "tracks", "Addicted to Love")</code>, <code>tracks</code> should have <code>"Addicted to Love"</code> as the last element.
|
||||||
testString: assert(updateRecords(1245, "tracks", "Addicted to Love")[1245]["tracks"].pop() === "Addicted to Love", 'After <code>updateRecords(1245, "tracks", "Addicted to Love")</code>, <code>tracks</code> should have <code>"Addicted to Love"</code> as the last element.');
|
testString: assert(updateRecords(1245, "tracks", "Addicted to Love")[1245]["tracks"].pop() === "Addicted to Love");
|
||||||
- text: After <code>updateRecords(2468, "tracks", "Free")</code>, <code>tracks</code> should have <code>"1999"</code> as the first element.
|
- text: After <code>updateRecords(2468, "tracks", "Free")</code>, <code>tracks</code> should have <code>"1999"</code> as the first element.
|
||||||
testString: assert(updateRecords(2468, "tracks", "Free")[2468]["tracks"][0] === "1999", 'After <code>updateRecords(2468, "tracks", "Free")</code>, <code>tracks</code> should have <code>"1999"</code> as the first element.');
|
testString: assert(updateRecords(2468, "tracks", "Free")[2468]["tracks"][0] === "1999");
|
||||||
- text: After <code>updateRecords(2548, "tracks", "")</code>, <code>tracks</code> should not be set
|
- text: After <code>updateRecords(2548, "tracks", "")</code>, <code>tracks</code> should not be set
|
||||||
testString: updateRecords(2548, "tracks", ""); assert(!collection[2548].hasOwnProperty("tracks"), 'After <code>updateRecords(2548, "tracks", "")</code>, <code>tracks</code> should not be set');
|
testString: updateRecords(2548, "tracks", ""); assert(!collection[2548].hasOwnProperty("tracks"));
|
||||||
- text: After <code>updateRecords(1245, "album", "Riptide")</code>, <code>album</code> should be <code>"Riptide"</code>
|
- text: After <code>updateRecords(1245, "album", "Riptide")</code>, <code>album</code> should be <code>"Riptide"</code>
|
||||||
testString: assert(updateRecords(1245, "album", "Riptide")[1245]["album"] === "Riptide", 'After <code>updateRecords(1245, "album", "Riptide")</code>, <code>album</code> should be <code>"Riptide"</code>');
|
testString: assert(updateRecords(1245, "album", "Riptide")[1245]["album"] === "Riptide");
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -51,38 +53,35 @@ tests:
|
|||||||
|
|
||||||
## Challenge Seed
|
## Challenge Seed
|
||||||
<section id='challengeSeed'>
|
<section id='challengeSeed'>
|
||||||
|
|
||||||
<div id='js-seed'>
|
<div id='js-seed'>
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// Setup
|
// Setup
|
||||||
var collection = {
|
var collection = {
|
||||||
"2548": {
|
2548: {
|
||||||
"album": "Slippery When Wet",
|
album: "Slippery When Wet",
|
||||||
"artist": "Bon Jovi",
|
artist: "Bon Jovi",
|
||||||
"tracks": [
|
tracks: [
|
||||||
"Let It Rock",
|
"Let It Rock",
|
||||||
"You Give Love a Bad Name"
|
"You Give Love a Bad Name"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"2468": {
|
2468: {
|
||||||
"album": "1999",
|
album: "1999",
|
||||||
"artist": "Prince",
|
artist: "Prince",
|
||||||
"tracks": [
|
tracks: [
|
||||||
"1999",
|
"1999",
|
||||||
"Little Red Corvette"
|
"Little Red Corvette"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"1245": {
|
1245: {
|
||||||
"artist": "Robert Palmer",
|
artist: "Robert Palmer",
|
||||||
"tracks": [ ]
|
tracks: [ ]
|
||||||
},
|
},
|
||||||
"5439": {
|
5439: {
|
||||||
"album": "ABBA Gold"
|
album: "ABBA Gold"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// Keep a copy of the collection for tests
|
|
||||||
var collectionCopy = JSON.parse(JSON.stringify(collection));
|
|
||||||
|
|
||||||
// Only change code below this line
|
// Only change code below this line
|
||||||
function updateRecords(id, prop, value) {
|
function updateRecords(id, prop, value) {
|
||||||
@ -97,51 +96,37 @@ updateRecords(5439, "artist", "ABBA");
|
|||||||
```
|
```
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
### After Test
|
|
||||||
<div id='js-teardown'>
|
|
||||||
|
|
||||||
```js
|
|
||||||
;(function(x) { return "collection = \n" + JSON.stringify(x, '\n', 2); })(collection);
|
|
||||||
```
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
## Solution
|
## Solution
|
||||||
<section id='solution'>
|
<section id='solution'>
|
||||||
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
var collection = {
|
var collection = {
|
||||||
2548: {
|
2548: {
|
||||||
album: "Slippery When Wet",
|
album: "Slippery When Wet",
|
||||||
artist: "Bon Jovi",
|
artist: "Bon Jovi",
|
||||||
tracks: [
|
tracks: [
|
||||||
"Let It Rock",
|
"Let It Rock",
|
||||||
"You Give Love a Bad Name"
|
"You Give Love a Bad Name"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
2468: {
|
2468: {
|
||||||
album: "1999",
|
album: "1999",
|
||||||
artist: "Prince",
|
artist: "Prince",
|
||||||
tracks: [
|
tracks: [
|
||||||
"1999",
|
"1999",
|
||||||
"Little Red Corvette"
|
"Little Red Corvette"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
1245: {
|
1245: {
|
||||||
artist: "Robert Palmer",
|
artist: "Robert Palmer",
|
||||||
tracks: [ ]
|
tracks: [ ]
|
||||||
},
|
},
|
||||||
5439: {
|
5439: {
|
||||||
album: "ABBA Gold"
|
album: "ABBA Gold"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// Keep a copy of the collection for tests
|
|
||||||
var collectionCopy = JSON.parse(JSON.stringify(collection));
|
|
||||||
|
|
||||||
// Only change code below this line
|
// Only change code below this line
|
||||||
function updateRecords(id, prop, value) {
|
function updateRecords(id, prop, value) {
|
||||||
|
Reference in New Issue
Block a user