Given an array arr of numbers, return the smallest number in the array. If the array is empty, return null.
Examples
Input: arr = [3, 1, 2]
Output: 1
Input: arr = [-5, 2, -3, 4]
Output: -5
Input: arr = [0, 2, 3]
Output: 0
Input: arr = []
Output: null
Constraints
- Input must be an array of finite numbers
- Return false for non-array inputs
- Return false for arrays containing non-number values
- Return false for arrays containing NaN, Infinity, or -Infinity
- For an empty array, return null
Function Signature
function findSmallest(arr) {
// Your code here
}
Test Cases
- Base cases: empty array [] -> null, single [ x ] -> x
- Mixed arrays: [ 3, 1, 2 ], [ -5, 2, -3, 4 ]
- All negatives: [ -1, -2, -3 ]
- All positives: [ 1, 2, 3 ]
- Decimals: [ -1.5, -0.1, 0, 2.2 ]
- Invalid inputs: null, undefined, 42, '8', {}, () => {}, [1, 'a'], [NaN], [Infinity]