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


TypeScript lodash.fill函數代碼示例

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


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

示例1: constructor

  constructor(iteratees = [], orders: SortOrder[] = [SortOrder.ASC]) {
    this.iteratees = iteratees;
    this.orders = orders;

    if (this.iteratees.length > this.orders.length) {
      let diff = this.iteratees.length - this.orders.length;
      let pad = this.orders[this.orders.length - 1];
      this.orders = _.concat(this.orders, _.fill(Array(diff), pad));
    }
  }
開發者ID:nfang,項目名稱:haru,代碼行數:10,代碼來源:query-command.ts

示例2: test

test('each chunk has the correct slice size', t => {
    let allLengths = _.flatten(_.map(chunks, chunk => _.map(chunk, 'length')));
    t.deepEqual(allLengths, _.fill(Array(12), 4));
});
開發者ID:rbcasperson,項目名稱:match-three-js,代碼行數:4,代碼來源:iterchunks.ts

示例3: getProfitResultsForTimestamp

  return _.map(marketPls, (outcomePLsAtTimestamp, timestampIndex) => {
    const nonZeroPositionOutcomePls = _.filter(outcomePLsAtTimestamp, (outcome) => !outcome.position.eq(ZERO));

    if (nonZeroPositionOutcomePls.length < 1) {
      return getProfitResultsForTimestamp(outcomePLsAtTimestamp, null, lastTradePriceMinusMinPrice24hAgoByOutcomeByMarketId, oldestTradePriceMinusMinPriceUserPaidForOpenPositionInLast24hByOutcomeByMarketId);
    }

    const numOutcomes = nonZeroPositionOutcomePls[0].numOutcomes;
    const outcomeValuesAtTimestamp = marketOutcomeValues ? marketOutcomeValues[timestampIndex] : _.fill(Array(numOutcomes), getDefaultOVTimeseries());

    // turn outcome values into real list
    const sortedOutcomeValues = _.reduce(_.range(numOutcomes), (result, outcomeIndex) => {
      let outcomeValue = _.find(outcomeValuesAtTimestamp, (ov) => ov.outcome === outcomeIndex);
      if (!outcomeValue) outcomeValue = Object.assign(getDefaultOVTimeseries(), { outcome: outcomeIndex });
      result.push(outcomeValue);
      return result;
    }, [] as Array<OutcomeValueTimeseries>);

    return getProfitResultsForTimestamp(outcomePLsAtTimestamp, sortedOutcomeValues, lastTradePriceMinusMinPrice24hAgoByOutcomeByMarketId, oldestTradePriceMinusMinPriceUserPaidForOpenPositionInLast24hByOutcomeByMarketId);
  });
開發者ID:AugurProject,項目名稱:augur_node,代碼行數:20,代碼來源:get-profit-loss.ts

示例4: emptyLine

 function emptyLine(): GraphLine {
   return fill(Array(graphSize), { value: GraphSymbol.Empty, color: "" });
 }
開發者ID:nicoespeon,項目名稱:gitgraph.js,代碼行數:3,代碼來源:index.ts

示例5: function

const murky: IMurky = function() {
  // like util.format without arguments
  if (arguments.length === 0)
    return ''

  // rawReplacers & fmtStr may be redefined in case if fmtStr is missed
  // look "like util.format without fmtStr" code block
  //
  // fmtStr may be extended in case if count(placeholders(fmtStr)) < rawReplacers.length
  // look "check psInfo and rawReplacer size" code block size
  const args = toArray(arguments)
  let fmtStr: string = args[0]
  let rawReplacers: Array<any> = args.slice(1)

  if (!isString(fmtStr)) {
    // like util.format without fmtStr
    rawReplacers = args
    fmtStr = fill(new Array(rawReplacers.length), '%s').join(' ')
  }

  // get placeholders info
  // psInfo may be
  // - truncated in case if psInfo.length gt rawReplacers.length
  // - extended  in case if psInfo.length lt rawReplacer.length
  let psInfo = extractAllPInfo(fmtStr)

  // check psInfo and rawReplacer size
  if (psInfo.length > rawReplacers.length) {
    // murky('%s %s', 123)
    psInfo = psInfo.slice(0, rawReplacers.length)
  } else if (psInfo.length < rawReplacers.length) {
    // murky('%s', 123, 345)
    const missedCount = rawReplacers.length - psInfo.length
    const missedPlaceholders = fill(new Array(missedCount), '%s').join(' ')
    fmtStr = fmtStr + ' ' + missedPlaceholders
    psInfo = extractAllPInfo(fmtStr)
  }

  // calc result string
  let replacers: Array<string> = []
  let positions: Array<number> = []
  let resStr = fmtStr

  rawReplacers.forEach((rawReplacer, index) => {
    const pInfo = psInfo[index]

    // calc current replacer position
    const rsLength = replacers
      .slice(0, index)
      .reduce((acc, replacer) => acc + replacer.length, 0)
    const psLength = psInfo
      .slice(0, index)
      .reduce((acc, pInfo) => acc + pInfo.placeholder.length, 0)
    const fmtPartLength = pInfo.indexStart
    const position = fmtPartLength - psLength + rsLength

    // get current replacer
    const replacer = handlers.processOne(
      resStr, pInfo, rawReplacer, position)

    // store for next iterations
    replacers.push(replacer)
    positions.push(position)

    // update result string
    const prev = resStr.substring(0, position)
    const post = resStr.substring(position + pInfo.length)
    resStr = prev + replacer + post
  })

  // normalize resStr
  resStr = resStr.replace(/%%/g, '%')

  // check replacers
  const rsOrderErrors = positions.map((posA, indexA) => {
    return positions.slice(0, indexA).map((posB, indexB) => {
      return { posB, indexB }
    }).filter(({ posB }) => {
      return posA !== posB
    }).filter(({ posB }) => {
      return posA <= posB
    }).map(({ posB, indexB }) => {
      return `wrong replacers order: A should be placed after B:\
        \n\t A index: ${indexA}\
        \n\t B index: ${indexB}\
        \n\t A data: ${inspect(posA)}\
        \n\t B data: ${inspect(posB)}`
    })
  }).reduce((acc, part) => acc.concat(part), [])

  const rsTypeErrors = replacers.map((replacer, index) => {
    return { replacer, index }
  }).filter(({ replacer }) => {
    return !isString(replacer)
  }).map(({ replacer, index }) => {
    return `replacer must be a string:
      \n\t index: ${index}\
      \n\t type: ${typeof replacer}\
      \n\t data: ${inspect(replacer)}`
  })
//.........這裏部分代碼省略.........
開發者ID:nskazki,項目名稱:murky,代碼行數:101,代碼來源:index.ts


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