Skip to content

Instantly share code, notes, and snippets.

@spcbfr
Created July 10, 2021 11:13
Show Gist options
  • Save spcbfr/ec0d63d0880c52f9247fea926adfd482 to your computer and use it in GitHub Desktop.
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
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