The aim of this project was to create a fun and engaging Javascript challenge that would test its user's ability to interact with object arguments and use the provided information to return an array of valid matches.
For this project, you are aiming to create a function that filters a list of countries based on the characteristics of their flags. The function, filterFlag, takes two arguments: an object containing the search terms (characteristics of the flag) and an array of flag data (FULL_FLAG_LIST). The function returns an array of country names that match the given characteristics.
- Installation
- Data Structure
- Testing
- Function Requirements
- Constraints
- Example Usage
- Evaluation Criteria
- Project Requirements
-
Clone the repository:
git clone git@github.com:samannetts8/Flagging-Down-the-Answer.git
-
Navigate to the project directory:
cd Flagging-Down-the-Answer -
Install the dependencies:
npm install
Each country's flag is represented by an object with the following keys:
country: stringhasStripes: booleannumberOfColors: inthasStars: booleanstripeDirection: string (can be "horizontal", "vertical" or null)hasCircles: booleancolours: [string, string, string] (an array containing varying number of strings)
To run the tests, use the following command:
npm testEnsure that Vitest is installed as a development dependency:
npm install --save-dev vitestEnsure that Vitest is installed as a development dependency:
The filterFlag function should:
- Handle input objects with varying sets of characteristics.
- Return the names of the countries that match the given characteristics.
Input Constraints:
- The function must handle input objects with up to 6 keys.
- Input will never be null.
- All input keys will have corresponding values in the
FULL_FLAG_LISTobject. - The function should return an array of strings representing country names.
Output Format:
- Output should be returned as a array of strings, e.g. ['Belgium', 'Germany', 'Venezuela', 'Romania']
filterFlag({hasStripes: true, hasCircles: true}, FULL_FLAG_LIST)should return['Argentina']as this is the only flag with both stripes and a circle.filterFlag({colours: ['red', 'yellow'], numberOfColors: 3}, FULL_FLAG_LIST)should return['Belgium', 'Germany', 'Venezuela', 'Romania'].filterFlag({hasStripes: false, numberOfColors: 2, stripeDirection: null}, FULL_FLAG_LIST)should return['China', 'European Union', 'Japan', 'Switzerland'].
- Correctness: Your code must pass all test cases
- Input will never be null
- All input keys will have a corresponding value in the object FULL_FLAG_LIST
- Design a full suite of tests to evaluate the proposed solution against various input objects.
- Ensure the function meets all technical constraints and limitations.
- Provide clear and comprehensive documentation for users and contributors.