Skip to content

Instantly share code, notes, and snippets.

@sondr3
Last active January 4, 2023 22:52
Show Gist options
  • Save sondr3/0bb3f60141e568553d45c1c40c135c16 to your computer and use it in GitHub Desktop.
Save sondr3/0bb3f60141e568553d45c1c40c135c16 to your computer and use it in GitHub Desktop.
Recursive
const findMin = nums => findMinRec(nums[0], nums);
const findMinRec = (curr, nums) => {
if (nums.length === 0) return curr;
const min = curr < nums[0] ? curr : nums[0];
return findMinRec(min, nums.splice(1))
}
console.log(findMin([1, 2, 3]))
console.log(findMin([-10, 42, 18, 37, 99, -100]))
console.log(findMin([-1, -2, -3]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment