From 1d5b89d27c2cb603a3ae9393ef23f269fdc3ad2d Mon Sep 17 00:00:00 2001
From: 30secondsofcode <30secondsofcode@gmail.com>
Date: Wed, 24 Jan 2018 15:39:36 +0000
Subject: [PATCH] Travis build: 1408
---
README.md | 4 ++--
docs/index.html | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/README.md b/README.md
index d01778d8b..16af20a52 100644
--- a/README.md
+++ b/README.md
@@ -4240,8 +4240,8 @@ const minBy = (arr, fn) => Math.min(...arr.map(typeof fn === 'function' ? fn : v
median([5, 6, 50, 1, -5]); // 5
Returns the minimum value of an array, after mapping each element to a value using the provided function.
Use Array.map() to map each element to the value returned by fn, Math.min() to get the maximum value.
const minBy = (arr, fn) => Math.min(...arr.map(typeof fn === 'function' ? fn : val => val[fn])); -
minBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], o => o.n); // 8 -minBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], 'n'); // 8 +
minBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], o => o.n); // 2 +minBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], 'n'); // 2
Uses the percentile formula to calculate how many numbers in the given array are less or equal to the given value.
Use Array.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