Skip to content

Commit

Permalink
Update products.js with straightforward code
Browse files Browse the repository at this point in the history
  • Loading branch information
bwreid committed Apr 27, 2023
1 parent d2d3ece commit 089ddb5
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/products.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,23 @@ function getFullName(contact) {
function getProductsPurchased(contact) {
const purchased = contact.purchased;

if (!purchased || !purchased.length) {
if (!purchased.length) {
return "No products purchased.";
}

if (purchased.length === 1) {
return purchased[0].name;
}

const result = [];
for (let product of purchased) {
result.push(product.name);
}

return result;
}

module.exports = {
getFullName,
getProductsPurchased,
};

0 comments on commit 089ddb5

Please sign in to comment.