Menu

gitpiper

percentile javascript Code Snippet in 2024

mathintermediate

Last Updated: 17 December 2024

Calculates the percentage of numbers in the given array that are less or equal to the given value.

  • Use Array.prototype.reduce() to calculate how many numbers are below the value and how many are the same value and apply the percentile formula.
const percentile = (arr, val) => (100 * arr.reduce( (acc, v) => acc + (v < val ? 1 : 0) + (v === val ? 0.5 : 0), 0 )) / arr.length;
percentile([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 6); // 55

javascript snippet similar to percentile For You in December 2024

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2024 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️