Created
July 10, 2021 11:13
-
-
Save spcbfr/ec0d63d0880c52f9247fea926adfd482 to your computer and use it in GitHub Desktop.
The solution to the free code camp challenge called "Record Collection", from the JavaScript Algorithms and Data Structures Course
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function updateRecords(records, id, prop, value) { | |
var record = records[id]; | |
if(prop !== "tracks" && value !== "") { | |
record[prop] = value; | |
} else if (value === ""){ | |
delete record[prop]; | |
} else if (prop == "tracks") { | |
if(record.hasOwnProperty("tracks") === false) { | |
record["tracks"] = []; | |
record["tracks"].push(value); | |
} else { | |
record["tracks"].push(value); | |
} | |
} | |
return records; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment