Lasso Soft Inc. > Home


AuthorBil Corry
LicensePublic Domain
Posted03 Dec 2005
Updated04 Dec 2005
More by this author...


Returns the median average value given an array of values.

Note: Requires [lp_integer_odd], [lp_decimal_precisionSet], and [lp_math_mean]

Sample Usage

(lp_math_median: (:10,2,3,4,1), 2);
'; (lp_math_median: (:10,2,4,6,7,1), 2);

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.


	-description='Returns the median average value given an array of values.',
	-required='numbers', -type='array',

	// did we get a precision?
		// nope, set it to zero
		local:'precision' = 0;

	// convert array of items into array of lp_decimals
	local:'numbers_array' = array;

	iterate: #numbers, local:'number';
		#numbers_array->(insert: (decimal: #number));

	// sort in order
	local:'midpoint' = integer:(math_ceil: (decimal: (decimal: #numbers_array->size) / (decimal: 2)));

	if: (lp_integer_odd: #numbers_array->size);
		return: (lp_decimal_precisionSet: (decimal: #numbers_array->(get: #midpoint)), (integer:#precision));		
	else; // even
		return: (lp_decimal_precisionSet: (lp_math_mean: (array:(decimal: #numbers_array->(get: #midpoint)),(decimal: #numbers_array->(get: #midpoint + 1)))) , (integer:#precision));



Related Tags


No comments

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home



©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft