Jump to content

JS Math."middle"


tiscavalcanti

Recommended Posts

Three given values? Why not use an exhaustive if-then-else construct?

 

Your question is oddly worded because you might also be implying the arithmetic average which is 45.45.

Link to comment
Share on other sites

You can either write your own function to return the median of an array, or you can use a library that includes one.

 

http://mathjs.org/docs/reference/functions/median.html

Thanks, but I believe which Math.median() don't work in After Effects Software by expression. I get a error ("Math.median is not a function").

 

 

Three given values? Why not use an exhaustive if-then-else construct?

 

Your question is oddly worded because you might also be implying the arithmetic average which is 45.45.

I could use if/else but, in my case, the values are not fixed, this value that I show is just example.

How i can do this between if/else?

Edited by tiscavalcanti
Link to comment
Share on other sites

Again, your question is oddly worded. Are you saying that you want to supply three values to a function and receive the "middle" value back?

function middle(a,b,c){
if ((a > b && a < c)||(a > c && a < B)){
return a;
}else if ((b > a && b < c)||(b > c && b < a)){
return b;
}else if ((c > a && c < B)||(c > b && c < a)){
return c;
}else{
 return -999; // if a = b or a = c or b = c
}

}//end of function
  • Like 1
Link to comment
Share on other sites

Again, your question is oddly worded. Are you saying that you want to supply three values to a function and receive the "middle" value back?

I want the value of a property of my program, to which this code is entered, is defined by the value of another property that is between two other properties, ie three properties, I do not even want Math.max or Math. min, but the value is between these two.

Link to comment
Share on other sites

Thanks, but I believe which Math.median() don't work in After Effects Software by expression. I get a error ("Math.median is not a function").

The website I linked to hosts the library which defines it. It is not built in to Javascript. They wrote their own function to do it, and you can download their library to define that method and whatever else the library includes. Or, like I said, write your own.
  • Like 1
Link to comment
Share on other sites

I want the value of a property of my program, to which this code is entered, is defined by the value of another property that is between two other properties, ie three properties, I do not even want Math.max or Math. min, but the value is between these two.

 

This would be much simpler if you actually provided an example of what you want this function to do. You seemed to do this in your first post above, but now I'm not sure.

Link to comment
Share on other sites

 

Again, your question is oddly worded. Are you saying that you want to supply three values to a function and receive the "middle" value back?

function middle(a,b,c){
if ((a > b && a < c)||(a > c && a < ){
return a;
}else if ((b > a && b < c)||(b > c && b < a)){
return b;
}else if ((c > a && c < ||(c > b && c < a)){
return c;
}else{
 return -999; // if a = b or a = c or b = c
}

}//end of function

Thanks for your time, my friend. This forum like ever, very efficient. Work very well. :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...