Skip to content

Instantly share code, notes, and snippets.

@coodoo
Created May 11, 2017 02:26
Show Gist options
  • Save coodoo/668da5491ba4b4803067b2274ab3e25f to your computer and use it in GitHub Desktop.
Save coodoo/668da5491ba4b4803067b2274ab3e25f to your computer and use it in GitHub Desktop.
從目標體脂推算理想體重與需減去的脂肪,用法為 weight( 100, 0.3, 0.2, 400 )
function weight(
currentWeight = 82,
currentRatio = 0.23,
targetRatio = 0.2,
dailyBurn = 400,
) {
const currentFat = currentWeight * currentRatio
const currentMuscle = currentWeight - currentFat
const targetWeight = currentMuscle / (1 - targetRatio)
const loseFat = currentWeight - targetWeight // kg
const calories = 7700 * loseFat // 大卡
const estimatedDays = Math.round(calories / dailyBurn)
return {
currentFat,
currentMuscle,
targetWeight,
loseFat,
estimatedDays: `${Math.floor(estimatedDays / 30)}month ${estimatedDays % 30}days`,
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment