codinasion-archive / codinasion-monorepo

Community Monorepo
https://codinasion.org
MIT License
52 stars 170 forks source link

FindLargestAndSmallestNumbersInAnArray.js the first function is not relevant to the task #4320

Closed pelegsch666 closed 1 year ago

pelegsch666 commented 1 year ago

Description

there is too much code in this file

Additional information

No response

Code of Conduct

codinasion-bot[bot] commented 1 year ago

👋🏻 Hey @pelegsch666

💖 Thanks for opening this issue 💖

A team member should be by to give feedback soon.

pelegsch666 commented 1 year ago

!assign

harshraj8843 commented 1 year ago

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

https://github.com/codinasion/program/blob/5b511ced7045bc757222fa7eb9482b2bfbdb8289/program/find-largest-and-smallest-numbers-in-an-array/FindLargestAndSmallestNumbersInAnArray.js#L1-L10

pelegsch666 commented 1 year ago

the function largesmall only sorting the array and doesnt return the values only the console log itself

patel-aum commented 1 year ago

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?

pelegsch666 commented 1 year ago

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);

patel-aum commented 1 year ago

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 🔥

patel-aum commented 1 year ago

@harshraj8843 can we update this code with this approach?

harshraj8843 commented 1 year ago

Yes, this approach is much better 😃