本文整理汇总了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;未经允许,请勿转载。 |
请发表评论