📊
Basic Number filtering exercise
This is a basic number-filtering exercise. To make the most of this exercise, look at only one story at a time, complete it, and move on to the next story. Try to do Test Driven Development (TDD) for this problem, if possible. If not TDD, at least write the test cases after writing the code - input and expected outputs are given in each story.
Story 1
Given a list of integers, write a program to return only the even numbers from this list.
Story 2
Given a list of integers, write a program to return only the odd numbers from this list.
Story 3
Given a list of integers, write a program to return only the prime numbers from this list.
Story 4
Given a list of integers, write a program to return only the odd prime numbers from this list.
Story 5
Given a list of integers, write a program to return only the even and multiples of 5 from this list.
Story 6
Given a list of integers, write a program to return only the odd and multiples of 3 greater than 10 from this list.
Story 7
Given a list of integers, and a set of conditions (odd, even, greater than 5, multiple of 3, prime, and many more such custom conditions that may be dynamically defined by user), write a program to return only the integers from the given list that match ALL the conditions.
Story 8
Given a list of integers, and a set of conditions (odd, even, greater than 5, multiple of 3, prime, and many more such custom conditions that may be dynamically defined by user), write a program to return only the integers from the given list that match ANY of the conditions.
Expectations
Write small modular functions (e.g. odd, even, prime, etc) to check if a particular number is odd, even or prime. These functions should take input a single number and return a bool.
Test-drive the code, i.e. write test cases before you write the implementation. Writing tests first will help you figure out function signature and edge cases, if any.
Identify expected input and output for this program. How will you accept the inputs to the program (e.g. via tests, or stdout or file) and where will the program produce the output (stdout, file, etc)?
Start by creating separate functions for each of the test cases.
Try to identify the common parts of the program - looping on input array and if, some set of conditions match, then add the number in the output array. Think how you will abstract this into some common structure.
Implement orchestration functions called “all” and “any” for Story 7 and 8. Does Go have such functions in collections library already? If yes, what are those and how do these work? If no, can you write such functions using Go’s generics? This way, the functions can work on any types, not just ints.