Last active
May 11, 2017 03:10
-
-
Save coodoo/47c405baeebf99f87c6fe496affcc20a to your computer and use it in GitHub Desktop.
從目標體脂推算理想體重與需減去的脂肪,用法為 weight( 100, 0.3, 0.2, 400 ),代表目前體重 100kg,體脂 30%,目標體脂 20%,每日運動可燒掉 400大卡。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: Math.round(targetWeight), | |
loseFat: Math.round( loseFat ), | |
estimatedDays: `${Math.floor(estimatedDays / 30)} month ${estimatedDays % 30} days`, | |
} | |
} | |
weight() | |
// { currentFat: 18.86, currentMuscle: 63.14, targetWeight: 78.925, loseFat: 3.075000000000003, estimatedDays: "1m 29d" } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment