-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjsonFileStorage.js
More file actions
46 lines (40 loc) · 1.52 KB
/
jsonFileStorage.js
File metadata and controls
46 lines (40 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//(Alcohol Content x Liquor Volume / Total Drink Volume) x 100 = % Alcohol by Volume
// const amount_arr = [2, .25, 1, .25]
// const abv_arr = [0.4, 0.2, 0, 0]
//function to calculate drink overall abv
export const calcStrength = (amount_arr, abv_arr) =>{
const amount = amount_arr.map(amt_arr=> parseFloat(amt_arr))
console.log(amount, abv_arr)
let alcContent = 0
amount.forEach((amt,index)=> {
alcContent += amt * abv_arr[index]
// console.log(amount,abv_arr[index], amount*abv_arr[index], alcContent)
})
const totalVol = amount.reduce((a,b)=> a+b)
const drinkAbv = alcContent / totalVol * 100
console.log(totalVol, alcContent, drinkAbv)
return drinkAbv
}
// calcStrength(amount_arr, abv_arr)
// const amount_arr = [2, .25, 1, .25]
// const flavor_arr = ["alcohol", "fruity", "fruity", "sweet"]
//function to calculate drink overall flavour type
export const flavorList = (amount_arr, flavor_arr)=>{
const amount = amount_arr.map(amt_arr=> parseFloat(amt_arr))
const flavObj = {sweet: 0, sour: 0, bitter:0, savory:0, spicy:0, fruity:0, overall_abv:0}
const totalVol = amount.reduce((a,b)=> a+b)
const amount_arrPerc = amount.map(amt=>(amt/totalVol))
// console.log(amount_arrPerc)
flavor_arr.forEach((flavor, index)=>{
if(flavor!=="alcohol"){
if (Object.keys(flavObj).includes(flavor)){
flavObj[flavor] += amount_arrPerc[index]
} else {
flavObj[flavor] = amount_arrPerc[index]
}
}
})
// console.log(flavObj)
return flavObj
}
// flavorList(amount_arr, flavour_arr)