function calculateUserList( userIdList , costList , conversionList , avg_cost ) {
// write code here
let len = userIdList.length
function doneList(n,len){
let k = new Array(len).fill(0)
let i = 0
if(n==0)return k
while(n!=1){
k[i]=n%2
n = (n-n%2)/2
i++
}
k[i] = 1
return k
}
let max = 0
let result = []
let pp = Math.pow(2,len)
//let list = doneList(0,len)
for(let i = 0;i<pp;i++){
//let i = 0
let list = doneList(i,len)
//console.log(list)
let sum = 0
let people = 0
//let sump = 0
for(let j = 0;j<len;j++){
if(list[j]==1){
sum+=costList[j]
people+=conversionList[j]
}
}
//console.log(sum)
//console.log(people)
if(sum/people<=avg_cost){
if(people>max){
max=people
result = list
}
}
}
//console.log(result)
let temp = []
for(let u = 0;u<len;u++){
if(result[u]==1){
temp.push(userIdList[u])
}
}
//console.log(doneList(3,4))
return temp
}
console.log(calculateUserList([1,2,3,4,5],[2.0, 3.0, 1.0, 4.0, 2.0],[0.2, 0.1, 0.2, 0.1, 0.4],9.5))
console