I have an array and an object and i would like a function samePrice(arr,obj) like this:
const arr = [0,1,2];
const obj = {
0: 10,
1: 10,
2: 10,
3: 12,
};
// samePrice(arr,obj) => true
const arr = [0,3];
const obj = {
0: 10,
1: 10,
2: 10,
3: 12,
};
// samePrice(arr,obj) => false
Here is my current function...
const samePrice = (arr,obj) => {
let result = true;
let it = obj[arr[0]];
arr.forEach(item => {
if (obj[item] !== it){
result = false;
}
})
return result;
}
I am sure there is a better solution.
(arr, obj) => false;needs only a single line ... What should the function actually do?