@supuwoerc/toolkit
    Preparing search index...

    Function normalize

    • 创建一个归一化函数,将给定范围内的值映射到 [0, 1] 区间 Creates a normalization function that maps values in a given range to [0, 1]

      Parameters

      • min: number

        范围的最小值 / Minimum value of the range

      • max: number

        范围的最大值 / Maximum value of the range

      Returns (n: number) => number

      归一化函数,接收一个数值并返回其在 [0, 1] 区间内的比例 Normalization function that takes a number and returns its proportion in [0, 1]

      当最大值小于或等于最小值时抛出异常 Throws an error when max is less than or equal to min

      // 示例 / Example:
      const normalizeToRange = normalize(10, 20)
      console.log(normalizeToRange(15)) // 输出: 0.5