Activity › Forums › Adobe After Effects Expressions › Find the Largest of 3 Values
-
Dan Ebberts
June 27, 2012 at 1:18 pmI think this works too:
Math.min(Math.min(Math.max(a,b),Math.max(a,c)),Math.max(b,c))
Dan
-
Walter Soyka
June 30, 2012 at 1:14 amHere’s an alternate approach, using arrays and the sort() method. First, stuff each of the values into an unsorted array. Next, sort the array. Finally, return the value of the last item in the array, which will be the highest value because we just sorted it.
unsortedArray = [a,b,c];
sortedArray = unsortedArray.sort();
sortedArray[sortedArray.length-1];To get the middle value, replace the final line with:
sortedArray[Math.round(sortedArray.length/2)-1];To get the lowest value, replace the final line with:
sortedArray[0];You can shorten it, too, removing the assignment:
myArray = [a,b,c];
myArray.sort()[sortedArray.length-1];Walter Soyka
Principal & Designer at Keen Live
Motion Graphics, Widescreen Events, Presentation Design, and Consulting
RenderBreak Blog – What I’m thinking when my workstation’s thinking
Creative Cow Forum Host: Live & Stage Events
Reply to this Discussion! Login or Sign Up