Created
February 12, 2021 02:33
-
-
Save theDreamer911/6a84a095bcbb32b014a67a888f9d540d to your computer and use it in GitHub Desktop.
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
// Solution One | |
smallest = (arr) => { | |
const sorted = arr.sort((a, b) => a - b); | |
const lowest = sorted[0]; | |
const highest = sorted[sorted.length - 1]; | |
return `lowest: ${lowest} \nhighest: ${highest}\n`; | |
}; | |
// Solution Two | |
smallest = (arr) => { | |
const lowest = Math.min(...arr); | |
const highest = Math.max(...arr); | |
return `lowest: ${lowest} \nhighest: ${highest}\n`; | |
}; | |
console.log(smallest([34, 15, 88, 2])); | |
console.log(smallest([34, -345, -1, 100])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment