Last active
January 4, 2023 22:52
-
-
Save sondr3/0bb3f60141e568553d45c1c40c135c16 to your computer and use it in GitHub Desktop.
Recursive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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