当前位置: 首页>>代码示例>>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;未经允许,请勿转载。