Smallest Product

Warmup

Given an array of integers, write a function that returns the smallest product of 3 numbers.

Example:

const input = [1,2,3,4]
smallestProduct(input) // --> returns 6

The smallest product that can be obtained is 6 because 1 * 2 * 3 equals 6. No other combination of numbers will produce a smaller product.

Constraints

The length of the array will always be at least three. The array may also contain negative numbers.

Test Cases

[1, 2, 3, 4] // --> should return 6
[30, 20, 10, 0] // --> should return 0
[-1, -2, -5, -6, -4] // --> should return -120
[ -1, 0, 2, -2, 3] // --> should return -12
[3, -4, 2, 1, 5] // -> should return -60