Skip to content

Instantly share code, notes, and snippets.

@theDreamer911
Created February 12, 2021 02:33
Show Gist options
  • Save theDreamer911/6a84a095bcbb32b014a67a888f9d540d to your computer and use it in GitHub Desktop.
Save theDreamer911/6a84a095bcbb32b014a67a888f9d540d to your computer and use it in GitHub Desktop.
// 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