Identifying Round Numbers in an Array
This challenge focuses on identifying "round numbers" within an array of integers. A round number is defined as a number where the last digit is zero. This problem is useful for data analysis scenarios where you might need to filter or categorize numbers based on their ending digit.
Problem Description
You are given an array of integers. Your task is to write a JavaScript function that takes this array as input and returns a new array containing only the round numbers from the original array. A round number is any integer that ends in zero (e.g., 10, 20, 100, 1000).
Key Requirements:
- The function must accept a single argument: an array of integers.
- The function must return a new array containing only the round numbers from the input array.
- The order of the round numbers in the output array should be the same as their order in the input array.
- The function should handle empty input arrays gracefully.
- The function should handle arrays containing non-integer values (though these should be ignored - only integers should be considered).
Expected Behavior:
The function should iterate through the input array, check if each element is an integer and if it ends in zero. If both conditions are met, the element should be added to the output array.
Edge Cases to Consider:
- Empty input array.
- Array containing only non-round numbers.
- Array containing a mix of round and non-round numbers.
- Array containing negative round numbers (e.g., -10, -20).
- Array containing zero (0) - this is a round number.
- Array containing non-integer values (e.g., strings, floats). These should be ignored.
Examples
Example 1:
Input: [10, 25, 30, 47, 50]
Output: [10, 30, 50]
Explanation: The numbers 10, 30, and 50 end in zero, so they are included in the output.
Example 2:
Input: [1, 2, 3, 4, 5]
Output: []
Explanation: None of the numbers end in zero, so the output array is empty.
Example 3:
Input: [-10, 0, 100, -20, 5, "hello", 3.14]
Output: [-10, 0, 100, -20]
Explanation: -10, 0, 100, and -20 are round numbers. "hello" and 3.14 are ignored because they are not integers.
Constraints
- The input array will contain integers and potentially other data types.
- The length of the input array can be up to 1000.
- The integers in the input array can range from -10000 to 10000.
- The function should execute in O(n) time complexity, where n is the length of the input array.
Notes
Consider using the modulo operator (%) to check if a number ends in zero. Remember to explicitly check if a value is an integer before performing the modulo operation to avoid unexpected behavior with non-integer values. Think about how to efficiently filter the array while maintaining the original order.