当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript lodash.last函数代码示例

本文整理汇总了TypeScript中lodash.last函数的典型用法代码示例。如果您正苦于以下问题:TypeScript last函数的具体用法?TypeScript last怎么用?TypeScript last使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了last函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: getProfitLossData

async function getProfitLossData(db: Knex, params: GetProfitLossParamsType): Promise<ProfitLossData> {
  const now = getCurrentTime();

  // Realized Profits + Timeseries data about the state of positions
  const profitsOverTime = await queryProfitLossTimeseries(db, now, params);
  const marketProfits = _.groupBy(profitsOverTime, (r) => r.marketId);
  const profits: Dictionary<Dictionary<Array<ProfitLossTimeseries>>> = _.reduce(marketProfits, (result, value, key) => {
    result[key] = _.groupBy(value, (r) => r.outcome);
    return result;
  }, {} as Dictionary<Dictionary<Array<ProfitLossTimeseries>>>);

  // Type there are no trades in this window then we'll return empty data
  if (_.isEmpty(profits)) {
    const buckets = bucketRangeByInterval(params.startTime || 0, params.endTime || now, params.periodInterval);
    return { profits: {}, outcomeValues: {}, buckets, lastTradePriceMinusMinPrice24hAgoByOutcomeByMarketId: {}, oldestTradePriceMinusMinPriceUserPaidForOpenPositionInLast24hByOutcomeByMarketId: {} };
  }

  // The value of an outcome over time, for computing unrealized profit and loss at a time
  const outcomeValuesOverTime = await queryOutcomeValueTimeseries(db, now, params);
  const marketOutcomeValues = _.groupBy(outcomeValuesOverTime, (r) => r.marketId);
  const outcomeValues: Dictionary<Dictionary<Array<OutcomeValueTimeseries>>> = _.reduce(marketOutcomeValues, (result, value, key) => {
    result[key] = _.groupBy(value, (r) => r.outcome);
    return result;
  }, {} as Dictionary<Dictionary<Array<OutcomeValueTimeseries>>>);

  // The timestamps at which we need to return results
  const startTime = params.startTime || profitsOverTime[0].timestamp;
  const maxResultTime = Math.max(_.last(profitsOverTime)!.timestamp, _.last(outcomeValuesOverTime)!.timestamp);
  const endTime = Math.min(maxResultTime, now);
  const interval = params.periodInterval || null;
  const buckets = bucketRangeByInterval(startTime, endTime, interval);

  return {
    profits,
    outcomeValues,
    buckets,
    lastTradePriceMinusMinPrice24hAgoByOutcomeByMarketId: await getLastTradePriceMinusMinPrice24hAgoByOutcomeByMarketId(db, now, params),
    oldestTradePriceMinusMinPriceUserPaidForOpenPositionInLast24hByOutcomeByMarketId: await getOldestTradePriceMinusMinPriceUserPaidForOpenPositionInLast24hByOutcomeByMarketId(db, now, params),
  };
}
开发者ID:AugurProject,项目名称:augur_node,代码行数:40,代码来源:get-profit-loss.ts

示例2: expect

 .then(resp => {
   const { metrics } = resp.data.source;
   expect(metrics.length).to.equal(1);
   const metric = first(metrics);
   expect(metric).to.have.property('id', 'hostCpuUsage');
   expect(metric).to.have.property('series');
   const series = first(metric.series);
   expect(series).to.have.property('id', 'user');
   expect(series).to.have.property('data');
   const datapoint = last(series.data);
   expect(datapoint).to.have.property('timestamp', 1547571720000);
   expect(datapoint).to.have.property('value', 0.0018333333333333333);
 });
开发者ID:,项目名称:,代码行数:13,代码来源:

示例3: last

 sortedLessons.forEach((lesson: ColoredLesson) => {
   for (let i = 0; i < rows.length; i++) {
     const rowLessons: ColoredLesson[] = rows[i];
     const previousLesson = last(rowLessons);
     if (!previousLesson || !doLessonsOverlap(previousLesson, lesson)) {
       // Lesson does not overlap with any Lesson in the row. Add it to row.
       rowLessons.push(lesson);
       return;
     }
   }
   // No existing rows are available to fit this lesson in. Append a new row.
   rows.push([lesson]);
 });
开发者ID:nusmodifications,项目名称:nusmods,代码行数:13,代码来源:timetables.ts

示例4: mapThreadToThreadSummary

function mapThreadToThreadSummary(state: ApplicationState, thread: Thread): ThreadSummaryVM {

  const lastMessageId = _.last(thread.messageIds),
    lastMessage = state.storeData.messages[lastMessageId];

  return {
    id: thread.id,
    participantNames: buildThreadParticipantsList(state, thread),
    lastMessageText: lastMessage.text,
    timestamp: lastMessage.timestamp,
    read: thread.id === state.uiState.currentThreadId || thread.participants[state.uiState.userId] === 0
  }
}
开发者ID:MidoShahin,项目名称:Chat-App-using-ngrx-store,代码行数:13,代码来源:stateToThreadSummeriesSelector.ts

示例5: createWaffleMapNode

export function createWaffleMapNode(node: InfraNode): InfraWaffleMapNode {
  const nodePathItem = last(node.path);
  if (!nodePathItem) {
    throw new Error('There must be at least one node path item');
  }
  return {
    pathId: node.path.map(p => p.value).join('/'),
    path: node.path,
    id: nodePathItem.value,
    name: nodePathItem.label || nodePathItem.value,
    metric: node.metric,
  };
}
开发者ID:lucabelluccini,项目名称:kibana,代码行数:13,代码来源:nodes_to_wafflemap.ts

示例6:

    return _.map(timestampeds, (values, outcome: string) => {
      let result: T | undefined;
      const beforeBucket = _.takeWhile(values, (pl) => pl.timestamp <= bucket.timestamp);
      if (beforeBucket.length > 0) {
        _.drop(values, beforeBucket.length);
        result = _.last(beforeBucket);
      }

      if (!result) result = Object.assign({ outcome }, defaultValue);
      result.timestamp = bucket.timestamp;

      return result;
    });
开发者ID:AugurProject,项目名称:augur_node,代码行数:13,代码来源:get-profit-loss.ts

示例7: getFields

const renderModel = (name, model = null) => {
  if (name.endsWith('[]')) {
    name = name.substr(0, name.length - 2);
  }
  if (model == null) {
    model = swagger.definitions[name];
  }
  let properties = model.properties
  if(properties == undefined) {
    properties = swagger.definitions[_.last<string>(model['$ref'].split('/'))].properties
  }
  return env.render('Model.cs', { name: name.replace(/\./g, '_'), fields: getFields(properties).map(f => renderField(f)) });
}
开发者ID:tylerlong,项目名称:rc-swagger-codegen,代码行数:13,代码来源:render.ts

示例8: pick

export function computeUndoStacks<T extends Record<string, any>>(
  state: UndoHistoryState = initialState,
  action: FSA,
  previousAppState: T,
  presentAppState: T,
  config: UndoHistoryConfig,
): UndoHistoryState {
  const { past, present, future } = state;

  // If action is undo/redoable, store state
  if (config.actionsToWatch.includes(action.type)) {
    // Append actual present to past, and drop history past config.limit
    // Limit only enforced here since undo/redo only shift the history around without adding new history
    const appendedPast = [...past, pick(previousAppState, config.whitelist)];
    const newPast = 'limit' in config ? takeRight(appendedPast, config.limit) : appendedPast;

    return {
      past: newPast,
      present: pick(presentAppState, config.whitelist),
      future: [],
    };
  }

  switch (action.type) {
    case UNDO: {
      // Abort if no past, or present is unknown
      if (past.length === 0 || !present) return state;
      const previous = last(past);
      const newPast = past.slice(0, past.length - 1);
      return {
        past: newPast,
        present: previous,
        future: [present, ...future],
      };
    }
    case REDO: {
      // Abort if no future, or present is unknown
      if (future.length === 0 || !present) return state;
      const next = future[0];
      const newFuture = future.slice(1);
      return {
        past: [...past, present],
        present: next,
        future: newFuture,
      };
    }
    default: {
      return state;
    }
  }
}
开发者ID:nusmodifications,项目名称:nusmods,代码行数:51,代码来源:undoHistory.ts


注:本文中的lodash.last函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。