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


TypeScript range.default函數代碼示例

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


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

示例1: createSource

  (common: StackInputSourceCommon, stage: GameStage | null, playerID: string[], currentRound: number, winMap: IPlayerMap<number>): IPlayerMap<Array<IDropdownSource<number>>> => {
    if (common) {
      return common
    }
    const defaultSrc = createSource(range(currentRound + 1))
    const winSum: number = sum(values(winMap))

    // Short circuit.
    // No-op when there is excess win
    // Or stage is not at waitingWin
    if (stage !== GameStage.waitingWin || winSum > currentRound) {
      return fillObj({}, playerID, defaultSrc)
    }

    // Surgery on win options
    // Cannot choose a win that exceed currentRound
    const delta = currentRound - winSum
    const head = createSource(range(delta + 1))
    const tail = range(delta + 1, currentRound + 1)
      .map(i => ({value: i, label: i + '', disabled: true}))
    const restSrc = head.concat(tail)

    const pairs = playerID
      .map(ID => {
        const selectedWin = winMap[ID]
        const src = (selectedWin <= 0 || selectedWin == null)
          ? restSrc
          : defaultSrc
        return [ID, src]
      })

    return fromPairs(pairs)
  }
開發者ID:Holi0317,項目名稱:bridge-calc,代碼行數:33,代碼來源:win-stack-input-source.ts

示例2: createSource

 (playerLength: number, selectedRounds: number): IEntrySource => {
   const maxRounds = Math.floor(52 / playerLength)
   const rounds = playerLength > 0
     ? createSource(range(1, maxRounds + 1))
     : defaultRounds
   const startingRound = playerLength > 0
     ? createSource(range(1, selectedRounds + 1))
     : defaultRounds
   return {
     rounds,
     startingRound
   }
 }
開發者ID:Holi0317,項目名稱:bridge-calc,代碼行數:13,代碼來源:options-sources.ts

示例3: createSource

  (common: StackInputSourceCommon, playerID: string[], currentRound: number, bidMap: IPlayerMap<number>, playerOrder: string[]): IPlayerMap<Array<IDropdownSource<number>>> => {
    if (common) {
      return common
    }
    const defaultSrc = createSource(range(currentRound + 1))
    const bid = fillObj({}, playerID, defaultSrc)
    const bidSum: number = sum(values(bidMap))

    // Surgery on bid options
    // Rules for bridge game. Last player cannot select the one that will cause sum == currentRound
    if (bidSum <= currentRound) {
      const lastPlayerID: string = last(playerOrder)!
      const delta = currentRound - bidSum
      const option = {value: delta, label: delta + '', disabled: true}

      // All bid in the map points to the same object. A clone on the map is needed before mutating it.
      const clonedOptions = bid[lastPlayerID].slice()
      clonedOptions[delta] = option
      bid[lastPlayerID] = clonedOptions
    }
    return bid
  }
開發者ID:Holi0317,項目名稱:bridge-calc,代碼行數:22,代碼來源:bid-stack-input-source.ts

示例4: changePlayersHandler

export function changePlayersHandler(rawState: IWaitingBidState | IWaitingWinState, {newNames, rounds, maker, time}: IChangePlayersAction): IWaitingBidState | IEndedState {
  // Short circuit. When action.rounds is less than current round
  if (rounds < rawState.currentRound) {
    // Tslint false positive on shallowed variable -- Shallowed variable on the else branch
    // tslint:disable-next-line: no-shadowed-variable
    const state = toEndedState(rawState, time)
    state.names = newNames
    state.rounds = rounds
    state.scores = mapValues(state.scores, (score: number[]) => score.slice(0, rounds))
    return state
  }

  const state = toWaitingBidState(rawState)
  state.rounds = rounds

  // Set currentPlayerOrder
  const newPlayerIDList = Object.keys(newNames)
  state.currentPlayerOrder = toFront(newPlayerIDList, newPlayerIDList.indexOf(maker))

  // Change scores
  const oldScores = state.scores
  const freshScores = range(state.currentRound - 1).fill(0) // Score for new players. I am terrible at naming.
  state.scores = mapValues(newNames, (_: string, ID: string): number[] => (
    (ID in oldScores)
      ? oldScores[ID]
      : freshScores
  ))

  // Change bid
  const oldBid = state.bid
  state.bid = mapValues(newNames, (_: string, ID: string): number => (
    (ID in oldBid)
      ? oldBid[ID]
      : 0
  ))

  // Change names field lastly
  state.names = newNames

  return state
}
開發者ID:Holi0317,項目名稱:bridge-calc,代碼行數:41,代碼來源:change-players-handler.ts

示例5: getEndedRounds

/**
 * Get number of rounds in forms of array that has ended.
 * Like range(endedRounds - 1).
 * For example, if currentRound is 1, then this will return [].
 * If currentRound is 2, then this will return [1].
 * If game has ended at round 13, the this will return [1..13].
 * Null state will return []
 */
function getEndedRounds(entry: NonNullable<GameState>): number[] {
  if (entry.stage === GameStage.ended) {
    return range(1, entry.rounds + 1)
  }
  return range(1, entry.currentRound)
}
開發者ID:Holi0317,項目名稱:bridge-calc,代碼行數:14,代碼來源:compute-data.ts


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