+ return (
+ (sortedDataSet[(sortedDataSet.length - 1) >> 1] +
+ sortedDataSet[sortedDataSet.length >> 1]) /
+ 2
+ )
+}
+
+/**
+ * Rounds the given number to the given scale.
+ * The rounding is done using the "round half away from zero" method.
+ *
+ * @param num - The number to round.
+ * @param scale - The scale to round to.
+ * @returns The rounded number.
+ * @internal
+ */
+export const round = (num: number, scale = 2): number => {
+ const rounder = Math.pow(10, scale)
+ return Math.round(num * rounder * (1 + Number.EPSILON)) / rounder
+}
+
+/**
+ * Is the given object a plain object?
+ *
+ * @param obj - The object to check.
+ * @returns `true` if the given object is a plain object, `false` otherwise.
+ * @internal
+ */
+export const isPlainObject = (obj: unknown): boolean =>
+ typeof obj === 'object' &&
+ obj !== null &&
+ obj?.constructor === Object &&
+ Object.prototype.toString.call(obj) === '[object Object]'
+
+/**
+ * Detects whether the given value is a kill behavior or not.
+ *
+ * @typeParam KB - Which specific KillBehavior type to test against.
+ * @param killBehavior - Which kind of kill behavior to detect.
+ * @param value - Any value.
+ * @returns `true` if `value` was strictly equals to `killBehavior`, otherwise `false`.
+ * @internal
+ */
+export const isKillBehavior = <KB extends KillBehavior>(
+ killBehavior: KB,
+ value: unknown
+): value is KB => {
+ return value === killBehavior
+}
+
+/**
+ * Detects whether the given value is an asynchronous function or not.
+ *
+ * @param fn - Any value.
+ * @returns `true` if `fn` was an asynchronous function, otherwise `false`.
+ * @internal
+ */
+export const isAsyncFunction = (
+ fn: unknown
+): fn is (...args: unknown[]) => Promise<unknown> => {
+ return typeof fn === 'function' && fn.constructor.name === 'AsyncFunction'
+}
+
+/**
+ * Generates a cryptographically secure random number in the [0,1[ range
+ *
+ * @returns A number in the [0,1[ range
+ * @internal
+ */
+export const secureRandom = (): number => {
+ return getRandomValues(new Uint32Array(1))[0] / 0x100000000
+}
+
+/**
+ * Returns the minimum of the given numbers.
+ * If no numbers are given, `Infinity` is returned.
+ *
+ * @param args - The numbers to get the minimum of.
+ * @returns The minimum of the given numbers.
+ * @internal
+ */
+export const min = (...args: number[]): number =>
+ args.reduce((minimum, num) => (minimum < num ? minimum : num), Infinity)
+
+/**
+ * Returns the maximum of the given numbers.
+ * If no numbers are given, `-Infinity` is returned.
+ *
+ * @param args - The numbers to get the maximum of.
+ * @returns The maximum of the given numbers.
+ * @internal
+ */
+export const max = (...args: number[]): number =>
+ args.reduce((maximum, num) => (maximum > num ? maximum : num), -Infinity)
+
+/**
+ * Wraps a function so that it can only be called once.
+ *
+ * @param fn - The function to wrap.
+ * @param context - The context to bind the function to.
+ * @returns The wrapped function.
+ * @internal
+ */
+// eslint-disable-next-line @typescript-eslint/no-explicit-any
+export const once = <T, A extends any[], R>(
+ fn: (...args: A) => R,
+ context: T
+): ((...args: A) => R) => {
+ let result: R
+ return (...args: A) => {
+ if (fn != null) {
+ result = fn.apply<T, A, R>(context, args)
+ ;(fn as unknown as undefined) = (context as unknown as undefined) =
+ undefined
+ }
+ return result