3151 Shares

# How would you write a function in javascript that picks the lowest number?

Topic: **How to write a function in javascript**June 25, 2019 / By Misti

**Question:**
how would i Write a function, getMax, that will accept a variable number of numeric arguments
and return the maximum value passed to it.
how would i Write a function, getMin, that will accept a variable number of numeric arguments
and return the minimum value passed to it.
andy how would write that

## Best Answers: How would you write a function in javascript that picks the lowest number?

**Lindsey | 10 days ago**
Ok, i'l write it here as well lol
function getMax(vars) {
return Math.max.apply(Math, vars);
}
function getMin(vars) {
return Math.min.apply(Math, vars);
}
maxnum = getMax([10,20]);
minnum = getMin([10,20]);
@henni o right well done haha just looked it up, odd behavior lol

👍 228 | 👎 10

Did you like the answer?

**How would you write a function in javascript that picks the lowest number?** Share with your friends

We found more questions related to the topic: **How to write a function in javascript**

**Originally Answered: How would you write a function in javascript that picks the lowest number?**
Ok, i'l write it here as well lol
function getMax(vars) {
return Math.max.apply(Math, vars);
}
function getMin(vars) {
return Math.min.apply(Math, vars);
}
maxnum = getMax([10,20]);
minnum = getMin([10,20]);
@henni o right well done haha just looked it up, odd behavior lol

**Originally Answered: How would you write a function in javascript that picks the lowest number?**
function getMin()
{
var min = arguments[0];
for (var i = 1; i < arguments.length; i++) {
if (arguments[i] < min) {
min = arguments[i];
}
}
return min;
}
@Andy: arguments is defined for all functions and it stores the list of parameters that are passed. It's particularly useful for writing variadic functions as I've above. If you find it doesn't work, then try calling it like so:
getMin(-1, 32, 141, -5);

**Kaitlin**
function getMin()
{
var min = arguments[0];
for (var i = 1; i < arguments.length; i++) {
if (arguments[i] < min) {
min = arguments[i];
}
}
return min;
}
@Andy: arguments is defined for all functions and it stores the list of parameters that are passed. It's particularly useful for writing variadic functions as I've above. If you find it doesn't work, then try calling it like so:
getMin(-1, 32, 141, -5);

👍 90 | 👎 6

**Originally Answered: Write the number of answers for this question?**
Smallest number that divides by all of these:
8*9*5*7 = 2520
Obviously, its multiples, 5040 and 7560 also divide by all of these.
So the answer is 3.

**Originally Answered: Write the number of answers for this question?**
If by 8, that includes 4 and 2. If by ten, that includes 5. If by 9, that includes 3. All the others are in those three: 5*7*8*9. So the LCM is 2520. So there are 3 of those possible.