I really need some help with a homework problem I have been given. I don't want answers to the question, but I would like some help with knowing what methods to use.
My problem is:
The product owner on your development team believes they've seen a pattern as to which customers purchase the most socks. To verify, you've been asked to write a function that processes an array of customer objects and return a new array that contains only customers that match ANY of the following criteria:
- name starts with a 'C' (upper or lowercase)
- address contains no undefined fields
- the city is Peoria and the state is AZ
- membership level is GOLD or PLATINUM unless the customer is younger than 29, then SILVER is okay too
The array of customer objects will have the following schema:
const customers = [
{
name: 'Sam',
address: {
street: '1234 W Bell Rd',
city: 'Phoenix',
zip: '85308',
state: 'AZ'
},
membershipLevel: 'GOLD',
age: 32
},
//more customers with the same schema
];
Note: The solution to this problem does not require the use of callbacks. You will also need to use dot notation to access the properties. For example, customers[0].name would return "Sam".
As you can see, I have to sort this array by a few different parameters involving strings and part of strings. However, I have tried and failed to use the typical Array.sort() method as I'm actually sorting the objects, and I can't find a method to sort objects by parts of a string. Additionally, I will need help keeping it all within a separate array.
The thing that I think would help me the most would be to give me the method I should use for each of the criteria in the problem above. If so, I can look up and hopefully learn the methods myself. I am willing to accept any and all advice. Thank you for your time in reading this and helping me.