im having trouble Implementing the function min that takes three numbers and return smallest, help!?
task 121
same here i need help
You have the Math builtin object that would do the trick here quite quickly.
Coderslang_Master Thanks, it required a bit of basic mathematics to get around
- Edited
I'm also struggling to get this one to pass.
my solution:
export const min = (a, b, c) => {
if (a < b && c) {
return a;
}
if (b < a && c) {
return b;
}
if (c < a && b) {
return c;
}
};
It physically seems to work when I run it, but I get to following 2 errors when I run tests:
The min function should return the minimum of 3 numbers.
min should not return undefined.
Any ideas?
Hacktinium what if a
is equal to b
and c
?
Gotchya 1 is not less than 1, so it's going to return 'undefined'.
a part of my solution
if (a < b) {
if (c < a) {
return c;
} else {
return a;
}
} else {bla bla bla}
Hacktinium exactly
@bulentala you should make sure that the function always returns something, even if all the arguments are equal
I tried so hard and got so far
But in the end it .......
export const min = (a, b, c) => {
if (b>c && a>c)
return (c);
if (a>b && c>b)
return (b);
if (b>a && c>a)
return (a);
if (a+b===c b+c===a c+a===b)
return (p);
if (a===b)
return (g);
if (b===c)
return (q);
if (c===a)
return (l);
}
still faced :
the min function should return the min of 3 numbers
min should not return undefined.
Beggin for help
Evgeny you can also make your code shorter by using "less than or equal" operator - <=
I had problems too, but I passed the task. Here my solution.
export const min = (a, b, c) => {
if (a <= b && a <= c) {
return a;
} else {
if (a >= b && b <= c) {
return b;
} else {
return c;
}
}
};
Greeting from Venezuela
Had issues, but here is my solution that worked.
export const min = (a, b, c) => {
if (a < b && a < c) {
return a;
} else if ( b < a && b < c) {
return b;
} else {
return c;
}
}
My solution if I may
export const min = (a, b, c) => {
if (a<b && a<c){
return (a);
} else
if (b<a && b<c){
return(b);
} else
if (c<a && c<b){
return(c);
} else
if (a===b && a===c && b==c){
return(a,b,c);
}
}
How i passed it ->
export const min = (a, b, c) => {
if (a < b) {
if (a < c) {
return a;
} else {
return c;
}
}
if (b < a) {
if (b < c) {
return b;
} else {
return c
}
}
if (c < a) {
if (c < b) {
return c;
} else {
return b
}
}
if (a === b && a === c && b === c) {
return a;
}
}
- Edited
This is the smallest code i can write so far.
{
if (a < b && a < c) return a;
else if (b < a && b < c) return b;
else return c;
}
- Edited
Esta es mi soluciรณn:
export const min = (a, b, c) => {
if (a < b && a < c) return a;
else if (b < c && b < a) return b;
else if (c < b && c < a) return c;
else return a or b or c;
}
}
Well i struggled with it at first but here's my solution
export const min = (a, b, c) => {
if((a < b) && (a < c)){
return a;
} else if((b < a) && (b < c)){
return b;
} else{
return c;
}
}