當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript array.findLastIndex函數代碼示例

本文整理匯總了TypeScript中core/util/array.findLastIndex函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript findLastIndex函數的具體用法?TypeScript findLastIndex怎麽用?TypeScript findLastIndex使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了findLastIndex函數的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: compute

  compute(x) {
    // Apply the transform to a single value
    let descending;
    this.sort(descending = false);

    if (this.clip === true) {
      if ((x < this._x_sorted[0]) || (x > this._x_sorted[this._x_sorted.length-1])) {
        return null;
      }
    } else {
      if (x < this._x_sorted[0]) {
        return this._y_sorted[0];
      }
      if (x > this._x_sorted[this._x_sorted.length-1]) {
        return this._y_sorted[this._y_sorted.length-1];
      }
    }

    if (x === this._x_sorted[0]) {
      return this._y_sorted[0];
    }

    const ind = findLastIndex(this._x_sorted, num => num < x);

    const x1 = this._x_sorted[ind];
    const x2 = this._x_sorted[ind+1];
    const y1 = this._y_sorted[ind];
    const y2 = this._y_sorted[ind+1];

    const ret = y1 + (((x-x1) / (x2-x1)) * (y2-y1));
    return ret;
  }
開發者ID:FourtekIT-incubator,項目名稱:bokeh,代碼行數:32,代碼來源:linear_interpolator.ts

示例2: compute

  compute(x: number): number {
    this.sort(false)

    if (this.clip) {
      if (x < this._x_sorted[0] || x > this._x_sorted[this._x_sorted.length-1])
        return NaN
    } else {
      if (x < this._x_sorted[0])
        return this._y_sorted[0]
      if (x > this._x_sorted[this._x_sorted.length-1])
        return this._y_sorted[this._y_sorted.length-1]
    }

    let ind: number
    switch (this.mode) {
      case "after": {
        ind = findLastIndex(this._x_sorted, num => x >= num)
        break
      }
      case "before": {
        ind = findIndex(this._x_sorted, num => x <= num)
        break
      }
      case "center": {
        const diffs = this._x_sorted.map((tx) => Math.abs(tx - x))
        const mdiff = min(diffs)
        ind = findIndex(diffs, num => mdiff === num)
        break
      }
      default:
        throw new Error(`unknown mode: ${this.mode}`)
    }

    return ind != -1 ? this._y_sorted[ind] : NaN
  }
開發者ID:Zyell,項目名稱:bokeh,代碼行數:35,代碼來源:step_interpolator.ts

示例3: compute

  compute(x: number): number {
    this.sort(false)

    if (this.clip) {
      if (x < this._x_sorted[0] || x > this._x_sorted[this._x_sorted.length-1])
        return NaN
    } else {
      if (x < this._x_sorted[0])
        return this._y_sorted[0]
      if (x > this._x_sorted[this._x_sorted.length-1])
        return this._y_sorted[this._y_sorted.length-1]
    }

    if (x == this._x_sorted[0])
      return this._y_sorted[0]

    const ind = findLastIndex(this._x_sorted, num => num < x)

    const x1 = this._x_sorted[ind]
    const x2 = this._x_sorted[ind+1]
    const y1 = this._y_sorted[ind]
    const y2 = this._y_sorted[ind+1]

    return y1 + (((x-x1) / (x2-x1)) * (y2-y1))
  }
開發者ID:Zyell,項目名稱:bokeh,代碼行數:25,代碼來源:linear_interpolator.ts

示例4: compute

  compute(x) {
    // Apply the transform to a single value
    let descending, ret;
    this.sort(descending = false);

    if (this.clip === true) {
      if ((x < this._x_sorted[0]) || (x > this._x_sorted[this._x_sorted.length-1])) {
        return(null);
      }
    } else {
      if (x < this._x_sorted[0]) {
        return this._y_sorted[0];
      }
      if (x > this._x_sorted[this._x_sorted.length-1]) {
        return this._y_sorted[this._y_sorted.length-1];
      }
    }

    let ind = -1;
    if (this.mode === "after") {
      ind = findLastIndex(this._x_sorted, num => x >= num);
    }

    if (this.mode === "before") {
      ind = findIndex(this._x_sorted, num => x <= num);
    }

    if (this.mode === "center") {
      const diffs = (this._x_sorted.map((tx) => Math.abs(tx - x)));
      const mdiff = min(diffs);
      ind = findIndex(diffs, num => mdiff === num);
    }

    if (ind !== -1) {
      ret = this._y_sorted[ind];
    } else {
      ret = null;
    }

    return(ret);
  }
開發者ID:FourtekIT-incubator,項目名稱:bokeh,代碼行數:41,代碼來源:step_interpolator.ts

示例5: _build_discontinuous_object

  _build_discontinuous_object(nanned_qs) {
    // _s is @xs, @ys, @sxs, @sys
    // an object of n 1-d arrays in either data or screen units
    //
    // Each 1-d array gets broken to an array of arrays split
    // on any NaNs
    //
    // So:
    // { 0: [x11, x12],
    //   1: [x21, x22, x23],
    //   2: [x31, NaN, x32]
    // }
    // becomes
    // { 0: [[x11, x12]],
    //   1: [[x21, x22, x23]],
    //   2: [[x31],[x32]]
    // }
    const ds = {};
    for (let i = 0, end = nanned_qs.length; i < end; i++) {
      ds[i] = [];
      let qs = copy(nanned_qs[i]);
      while (qs.length > 0) {

        let qs_part;
        const nan_index = findLastIndex(qs, (q) => isStrictNaN(q));

        if (nan_index >= 0) {
          qs_part = qs.splice(nan_index);
        } else {
          qs_part = qs;
          qs = [];
        }

        const denanned = qs_part.filter((q) => !isStrictNaN(q))
        ds[i].push(denanned)
      }
    }
    return ds;
  }
開發者ID:FourtekIT-incubator,項目名稱:bokeh,代碼行數:39,代碼來源:patches.ts

示例6: _build_discontinuous_object

  private _build_discontinuous_object(nanned_qs: number[][]): number[][][] {
    // _s is this.xs, this.ys, this.sxs, this.sys
    // an object of n 1-d arrays in either data or screen units
    //
    // Each 1-d array gets broken to an array of arrays split
    // on any NaNs
    //
    // So:
    // { 0: [x11, x12],
    //   1: [x21, x22, x23],
    //   2: [x31, NaN, x32]
    // }
    // becomes
    // { 0: [[x11, x12]],
    //   1: [[x21, x22, x23]],
    //   2: [[x31],[x32]]
    // }
    const ds: number[][][] = []
    for (let i = 0, end = nanned_qs.length; i < end; i++) {
      ds[i] = []
      let qs = copy(nanned_qs[i])
      while (qs.length > 0) {
        const nan_index = findLastIndex(qs, (q) => isStrictNaN(q))

        let qs_part
        if (nan_index >= 0)
          qs_part = qs.splice(nan_index)
        else {
          qs_part = qs
          qs = []
        }

        const denanned = qs_part.filter((q) => !isStrictNaN(q))
        ds[i].push(denanned)
      }
    }
    return ds
  }
開發者ID:gully,項目名稱:bokeh,代碼行數:38,代碼來源:patches.ts


注:本文中的core/util/array.findLastIndex函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。