+ 31

Getting the maximum number out of a list of numbers!

I need someone to show me an example of a function that returns the maximum number out of any given amount of parameters. NOTE:please do not use predefined functions like Math.max() e.t.c Do not use anything from Math library,create your own functions from scratch.This is not a challenge,i just need help😊Thanks!

25th Feb 2018, 6:45 PM
᠌᠌Code X
᠌᠌Code X - avatar
58 Antworten
+ 14
There's a few things that would determine the best way to do that including how are the arguments being passed in ie as in an array vector or individual arguments. if your passing as an array or placing them in an array the easiest method is to do a sort placing them in order.
25th Feb 2018, 7:14 PM
Michael Simnitt
Michael Simnitt - avatar
+ 30
//old code , get some idea from it //its for minimum , but no difference of logic used https://code.sololearn.com/c4T4311YtAQQ/?ref=app
25th Feb 2018, 7:07 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 21
Can I use Array methods (Array.prototype.reduce)? https://code.sololearn.com/Wz78NUTnIIH3/?ref=app
27th Feb 2018, 6:01 AM
Swapnil Srivastava
Swapnil Srivastava - avatar
+ 16
The most basic way I can think of is this https://code.sololearn.com/Wj1VzZWJ6sE5/?ref=app
25th Feb 2018, 7:06 PM
Mickel
Mickel - avatar
27th Feb 2018, 7:38 AM
The Coding Sloth
The Coding Sloth - avatar
+ 13
https://code.sololearn.com/c3ALOI412dGu/?ref=app
25th Feb 2018, 8:31 PM
Med Arezki
Med Arezki - avatar
+ 12
what does knowing the strength and weakness of JavaScript have to do here?I'm returning the closest IP addresses of individuals,something the "standard library function" cannot do,thats why I need to know how it works so I can modify it.
25th Feb 2018, 7:02 PM
᠌᠌Code X
᠌᠌Code X - avatar
26th Feb 2018, 12:06 AM
Vukan
Vukan - avatar
+ 12
take a variable max with value of 0 and put conditional statement example: int max=0; using loop according to your question { if(number>max) { max=number; } update your number; } your work is doooone!😊
26th Feb 2018, 10:00 AM
Aditya
Aditya - avatar
25th Feb 2018, 6:53 PM
Vlad Zadorozhnyi
Vlad Zadorozhnyi - avatar
+ 10
@Brains, you didn't tag the question, so is the question for Java or JavaScript? or other language?
25th Feb 2018, 8:17 PM
Ipang
+ 10
The first thing that comes to my mind is this: https://code.sololearn.com/csPGq6fm4oca/?ref=app
25th Feb 2018, 11:08 PM
Pedro Demingos
Pedro Demingos - avatar
+ 9
oohhh...a sort,thanks Micheal,didnt think of that
25th Feb 2018, 7:17 PM
᠌᠌Code X
᠌᠌Code X - avatar
25th Feb 2018, 7:19 PM
Baraa AB
Baraa AB - avatar
+ 8
write in your array as the function's argument https://code.sololearn.com/Wcujj23Iz5S7/?ref=app
26th Feb 2018, 10:14 AM
Nomeh Uchenna Gabriel
Nomeh Uchenna Gabriel - avatar
+ 8
https://code.sololearn.com/compq9ELbTq7/?ref=app Maybe I'm the only one here who suffers with python and tries ruby 😓
26th Feb 2018, 1:19 PM
DAB
DAB - avatar
+ 7
Assuming JavaScript, you can use arguments object for functions with variable number of arguments. function foo() { if(arguments.length < 1) return 0; var rv = arguments[0] < 0 ? 0 : arguments[0]; for(i = 0; i < arguments.length; i++) if(rv < arguments[i]) rv = arguments[i]; return rv; } window.onload = function() { console.log(foo(-5,-3,-1,0,1,3,5)); console.log(foo(26,2,2018)); console.log(foo(1,2,4,8)); console.log(foo(-10)); console.log(foo()); }; I still don't get what this has to do with IP number though : )
26th Feb 2018, 2:01 AM
Ipang
+ 7
array=[a,b,c,...,x] count=size(array) max= minimum posible value for(indx=1 to count) if array[indx] > max max=array[indx] position=indx end end pseudocode 😀
27th Feb 2018, 2:22 AM
⏩▶Clau◀⏪
⏩▶Clau◀⏪ - avatar
27th Feb 2018, 6:24 PM
Oma Falk
Oma Falk - avatar
+ 6
It can be done by sorting the list in ascending or descending order.. and print the first or last number
25th Feb 2018, 9:19 PM
Devvrat Marwah
Devvrat Marwah - avatar