Record Collection - JavaScript Algorithms and Data Structures | FreeCodeCamp Solution
#freeCodeCamp #JavaScriptDSA
📌 Link : https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/record-collection
🚨Problem Statement:
You are given an object literal representing a part of your musical album collection. Each album has a unique id number as its key and several other properties. Not all albums have complete information.
You start with an updateRecords function that takes an object literal, records, containing the musical album collection, an id, a prop (like artist or tracks), and a value. Complete the function using the rules below to modify the object passed to the function.
Your function must always return the entire record collection object.
If prop isn't tracks and value isn't an empty string, update or set that album's prop to value.
If prop is tracks but the album doesn't have a tracks property, create an empty array and add value to it.
If prop is tracks and value isn't an empty string, add value to the end of the album's existing tracks array.
If value is an empty string, delete the given prop property from the album.
Note: A copy of the recordCollection object is used for the tests.
📢Solution :
// Setup
var recordCollection = {
2548: {
albumTitle: 'Slippery When Wet',
artist: 'Bon Jovi',
tracks: ['Let It Rock', 'You Give Love a Bad Name']
},
2468: {
albumTitle: '1999',
artist: 'Prince',
tracks: ['1999', 'Little Red Corvette']
},
1245: {
artist: 'Robert Palmer',
tracks: []
},
5439: {
albumTitle: 'ABBA Gold'
}
};
// Only change code below this line
function updateRecords(records, id, prop, value) {
if(prop != "tracks" && value.length != 0){
records[id][prop] = value;
}
else if(prop === "tracks" && !records[id].hasOwnProperty(prop)){
records[id][prop] = [];
records[id][prop].push(value);
}
else if(prop === "tracks" && value.length != 0){
records[id][prop].push(value);
}
else if(value.length === 0){
delete records[id][prop];
}
return records;
}
Видео Record Collection - JavaScript Algorithms and Data Structures | FreeCodeCamp Solution канала Trending Youth
📌 Link : https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/record-collection
🚨Problem Statement:
You are given an object literal representing a part of your musical album collection. Each album has a unique id number as its key and several other properties. Not all albums have complete information.
You start with an updateRecords function that takes an object literal, records, containing the musical album collection, an id, a prop (like artist or tracks), and a value. Complete the function using the rules below to modify the object passed to the function.
Your function must always return the entire record collection object.
If prop isn't tracks and value isn't an empty string, update or set that album's prop to value.
If prop is tracks but the album doesn't have a tracks property, create an empty array and add value to it.
If prop is tracks and value isn't an empty string, add value to the end of the album's existing tracks array.
If value is an empty string, delete the given prop property from the album.
Note: A copy of the recordCollection object is used for the tests.
📢Solution :
// Setup
var recordCollection = {
2548: {
albumTitle: 'Slippery When Wet',
artist: 'Bon Jovi',
tracks: ['Let It Rock', 'You Give Love a Bad Name']
},
2468: {
albumTitle: '1999',
artist: 'Prince',
tracks: ['1999', 'Little Red Corvette']
},
1245: {
artist: 'Robert Palmer',
tracks: []
},
5439: {
albumTitle: 'ABBA Gold'
}
};
// Only change code below this line
function updateRecords(records, id, prop, value) {
if(prop != "tracks" && value.length != 0){
records[id][prop] = value;
}
else if(prop === "tracks" && !records[id].hasOwnProperty(prop)){
records[id][prop] = [];
records[id][prop].push(value);
}
else if(prop === "tracks" && value.length != 0){
records[id][prop].push(value);
}
else if(value.length === 0){
delete records[id][prop];
}
return records;
}
Видео Record Collection - JavaScript Algorithms and Data Structures | FreeCodeCamp Solution канала Trending Youth
Показать
Комментарии отсутствуют
Информация о видео
Другие видео канала
![How to Download Chrome on Windows 11 | Download Chrome Browser (Windows 11)](https://i.ytimg.com/vi/-7A49XjkHTU/default.jpg)
![🎮 How to Make Super Cool Gaming Logo on Android (Very Easy)](https://i.ytimg.com/vi/7Q9WeY8y92I/default.jpg)
![Top Three Python Projects For Beginners 2021 (Latest)](https://i.ytimg.com/vi/J89cTITCHkA/default.jpg)
![Secure your Divice...!!! 👮](https://i.ytimg.com/vi/CQGK13NDag4/default.jpg)
![Easiest Way To Swap Two Variables in C++ | Not Using TEMP | Using Bitwise XOR Operator To SWAP](https://i.ytimg.com/vi/15aLH9EkSbA/default.jpg)
![FAU-G 1st Mission | Uncut (Hindi)](https://i.ytimg.com/vi/-w6PpB4vNJM/default.jpg)
![p.u.b.g In 500 MB for android.](https://i.ytimg.com/vi/2nMNNmcILwg/default.jpg)
![How to bring This PC icon on desktop in windows 11](https://i.ytimg.com/vi/fkXNHwgEsEE/default.jpg)
![VS Code now opens on Browsers Directly | No need to download VS Code anymore](https://i.ytimg.com/vi/pm6ZY8XfE1E/default.jpg)
![How to add map in HTML (Easiest Way) | How to add map on your Website | HTML map adding tutorial](https://i.ytimg.com/vi/mb9ritEFSWo/default.jpg)
![Zomato Bug Bounty - $4000 (Approx. 3 Lakh Rupees) | Zomato Offering 3 Lakh Rupees To Catch Bugs](https://i.ytimg.com/vi/VdB7wfv_KHs/default.jpg)
![Can Windows 7 users upgrade to Windows 11?](https://i.ytimg.com/vi/1hQB0CDw6o0/default.jpg)
![Infosys: Calling Their Employees Back To Office [Latest News]](https://i.ytimg.com/vi/QzCRCaQREPc/default.jpg)
![BGMI Lite Coming Soon](https://i.ytimg.com/vi/mfb5wGyy9Do/default.jpg)
![wifi not showing in windows 10 (Solution)](https://i.ytimg.com/vi/WrxbAVPWYDk/default.jpg)
![How to get this Label in Instagram, below your username | Instagram Tips & Tricks | Category Label |](https://i.ytimg.com/vi/LN21eNWy30A/default.jpg)
![Nokia's top 4 smartphones 2018 ¦¦ latest updates.¦¦#Ep2](https://i.ytimg.com/vi/Rh4WYoaztYQ/default.jpg)
![Android P ¦¦ latest upcoming android version 2018](https://i.ytimg.com/vi/-qVa5wQUW-w/default.jpg)
![What Happen's If You Don't Delete Tik Tok || or Installed Tik Tok Before Ban in India 🇮🇳](https://i.ytimg.com/vi/HUoNy-T1ubo/default.jpg)
![Craziest😝 PUBG Training gameplay ever😱](https://i.ytimg.com/vi/pVJb0Q6uXN4/default.jpg)
![How to Stop Windows Updates. || "Ultimate Guide".](https://i.ytimg.com/vi/a23wnvoKg4w/default.jpg)