@revolugo/common 7.7.2-alpha.2 → 7.7.2-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@revolugo/common",
3
- "version": "7.7.2-alpha.2",
3
+ "version": "7.7.2-alpha.3",
4
4
  "private": false,
5
5
  "description": "Revolugo common",
6
6
  "author": "Revolugo",
@@ -29,6 +29,7 @@ export * from './get-sanitized-room-count.ts'
29
29
  export * from './get-user-ip-address.ts'
30
30
  export * from './group-by.ts'
31
31
  export * from './images.ts'
32
+ export * from './iqr.ts'
32
33
  export * from './is-empty.ts'
33
34
  export * from './is-equal.ts'
34
35
  export * from './is-nil.ts'
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Compute the value at quantile `p` (0–1) of a pre-sorted numeric array
3
+ * using linear interpolation (same method as R's type-7 / Excel PERCENTILE).
4
+ */
5
+ export function quartile(sorted: number[], p: number): number {
6
+ const n = sorted.length
7
+ const pos = (n - 1) * p
8
+ const base = Math.floor(pos)
9
+ const rest = pos - base
10
+ const baseValue = sorted[base] ?? 0
11
+ const nextValue = sorted[base + 1]
12
+
13
+ return (
14
+ baseValue + (nextValue === undefined ? 0 : rest * (nextValue - baseValue))
15
+ )
16
+ }
17
+
18
+ /**
19
+ * Compute the Tukey IQR upper bound for an array of values.
20
+ * upperBound = Q3 + coefficient × (Q3 − Q1)
21
+ *
22
+ * @param values Unsorted array of numbers (must have ≥ 4 elements).
23
+ * @param coefficient IQR multiplier (e.g. 1.5 = mild, 3 = extreme, 100 = ultra-permissive).
24
+ */
25
+ export function iqrUpperBound(values: number[], coefficient: number): number {
26
+ const sorted = [...values].sort((a, b) => a - b)
27
+ const q1 = quartile(sorted, 0.25)
28
+ const q3 = quartile(sorted, 0.75)
29
+ return q3 + coefficient * (q3 - q1)
30
+ }