There is an array of numbers: 1,5,5,10,5,8,3,4. Is there a formula to get the n % of it closest to the average? For this example average is ~5, and if I want 50% to be counted, numbers 3,4,5 should stay and numbers 1, 8, 10 should be dropped.
Is there a formula or algorithm to do this for K entries and n percent?