Advertisement
Guest User

Untitled

a guest
Aug 24th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 KB | None | 0 0
  1. // Total Daily Energy Expenditure
  2. function TDEE (data) {
  3. this.weight = data.weight || 60
  4. this.height = data.height || 180
  5. this.age = data.age || 20
  6. this.sex = data.sex || 'male'
  7. this.bodyType = data.bodyType || 'ectomorph'
  8. this.numberOfWorkouts = data.numberOfWorkouts || 3
  9. this.durationOfWorkout = data.durationOfWorkout || 45
  10. this.ratios = data.ratios || {
  11. protein: 35,
  12. carb: 45,
  13. fat: 20
  14. }
  15. }
  16.  
  17. // Basal Metabolic Rate
  18. TDEE.prototype.calculateBMR = function () {
  19. var weightFactor = 9.99
  20. var heightFactor = 6.25
  21. var ageFactor = 4.92
  22.  
  23. var result = ((weightFactor * this.weight) + (heightFactor * this.height) - (ageFactor * this.age))
  24.  
  25. return Math.floor(this.sex == 'male' ? result + 5 : result - 161)
  26. }
  27.  
  28. // calories used during physical activity
  29. TDEE.prototype.calculateTEA = function () {
  30. // strength exercises consume 7 - 9 kcal/minute
  31. var kcalpm = 9
  32. // EPOC calories used after workout, ~ 4% - 7% total calories intake
  33. var percentOfBMR = Math.floor((7 * this.calculateBMR()) / 100)
  34. var EPOC = (this.numberOfWorkouts * percentOfBMR)
  35. // console.log(EPOC)
  36.  
  37. // 3x60 mins x 9kcal + EPOC(3x(0.07 x calculateBMR))
  38. // results are divided by number of weekdays
  39. return Math.floor((this.numberOfWorkouts * this.durationOfWorkout * kcalpm + EPOC) / 7)
  40. }
  41.  
  42. // NEAT - thermogenesis not including workouts
  43. TDEE.prototype.calculateNEAT = function () {
  44. var body = {
  45. endomorph: 400, // endomorph 200-400 kcal
  46. ectomorph: 900, // ectomorph 700-900 kcal
  47. mesomorph: 500 // mesomorph 400-500 kcal
  48. }
  49.  
  50. return body[this.bodyType]
  51. }
  52.  
  53. TDEE.prototype.getMacronutrients = function () {
  54. var calories = this.getTotal()
  55. return {
  56. protein: Math.floor(calories * this.ratios.protein / 100 / 4),
  57. carb: Math.floor(calories * this.ratios.carb / 100 / 4),
  58. fat: Math.floor(calories * this.ratios.fat / 100 / 9)
  59. }
  60. }
  61.  
  62. TDEE.prototype.getTotal = function () {
  63. var BMR = this.calculateBMR()
  64. var TEA = this.calculateTEA()
  65. var NEAT = this.calculateNEAT()
  66. var total = BMR + TEA + NEAT
  67. // postmeal thermogenesis
  68. var TEF = Math.floor(total / 10)
  69.  
  70. return total + TEF
  71. }
  72.  
  73. var ratios = [
  74. {
  75. name: 'high-carb for bodybuilding',
  76. carb: 50, // 40-60
  77. protein: 30, // 25-35
  78. fat: 20 // 15-25
  79. },
  80. {
  81. name: 'moderate-carb for maitenance',
  82. carb: 40, // 30-50
  83. protein: 30, // 25-35
  84. fat: 30 // 25-35
  85. },
  86. {
  87. name: 'low-carb for reduction',
  88. carb: 20, // 10-20
  89. protein: 50, // 40-50
  90. fat: 30 // 30-40
  91. }
  92. ]
  93.  
  94. var qmmr = {
  95. weight: 84.8,
  96. height: 184,
  97. age: 34,
  98. sex: 'male',
  99. bodyType: 'mesomorph',
  100. numberOfWorkouts: 4,
  101. durationOfWorkout: 120,
  102. ratios: ratios[0]
  103. }
  104.  
  105. var tdee = new TDEE(qmmr)
  106. console.log('BMR: ', tdee.calculateBMR())
  107. console.log('TEA: ', tdee.calculateTEA())
  108. console.log('NEAT: ', tdee.calculateNEAT())
  109. console.log('TOTAL: ' + tdee.getTotal() + ' kcal')
  110. console.log('Chosen ratio -> ' + qmmr.ratios.name + ':')
  111. console.log('carb: ' + qmmr.ratios.carb + '%')
  112. console.log('protein: ' + qmmr.ratios.protein + '%')
  113. console.log('fat: ' + qmmr.ratios.fat + '%')
  114. console.log('Your daily macronutrients:')
  115. console.log('Proteins: ' + tdee.getMacronutrients().protein + 'g')
  116. console.log('Carbs: ' + tdee.getMacronutrients().carb + 'g')
  117. console.log('Fats: ' + tdee.getMacronutrients().fat + 'g')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement