Files
gold_land_user/src/modules/gold-land/lesson/growthTable.ts
T

22 lines
727 B
TypeScript
Raw Normal View History

const PERSIAN_DIGITS = '۰۱۲۳۴۵۶۷۸۹'
export function formatCoinTenths(tenths: number): string {
const abs = Math.abs(Math.trunc(tenths))
const whole = Math.floor(abs / 10)
const fraction = abs % 10
const plain = fraction === 0 ? String(whole) : `${whole}.${fraction}`
return plain.replace(/\d/g, (digit) => PERSIAN_DIGITS[Number(digit)] ?? digit).replace('.', '٫')
}
export function revealPeriods<T>(periods: T[], shown: number): T[] {
return periods.slice(0, Math.max(0, Math.min(shown, periods.length)))
}
export function nextShown(shown: number, total: number): number {
return Math.min(total, shown + 1)
}
export function previousShown(shown: number): number {
return Math.max(1, shown - 1)
}