Closed pelegsch666 closed 1 year ago
👋🏻 Hey @pelegsch666
💖 Thanks for opening this issue 💖
A team member should be by to give feedback soon.
!assign
Hey @pelegsch666
Could you please explain the purpose of this issue 🤔
File https://github.com/codinasion/program/blob/master/program/find-largest-and-smallest-numbers-in-an-array/FindLargestAndSmallestNumbersInAnArray.js seems right
the function largesmall only sorting the array and doesnt return the values only the console log itself
function largeSmall(numbers) {
let sorted = numbers.slice().sort(function (a, b) {
return a - b;
});
let smallest = sorted[0];
let largest = sorted[sorted.length - 1];
return console.log(${largest} ${smallest}
);
}
let numbers = [1, 2, 3, 4, 5]; largeSmall(numbers);
the function largesmall only sorting the array and doesnt return the values only the console log itself
@pelegsch666 you are suggesting something like thiss right?
i have a better solution function findingSmallestLargest(numArr) { console.log(Math.max(...numArr), Math.min(...numArr));
} //those are for testing purpose const numberArrTest = [1, 2, 3, 4, 5]; findingSmallLarge(numberArrTest);
Okay your approach is more direct and doesn't require creating a sorted copy of the array, so it may be faster and more efficient for large arrays. Good 🔥
@harshraj8843 can we update this code with this approach?
Yes, this approach is much better 😃
Description
there is too much code in this file
Additional information
No response
Code of Conduct