You’re very close. In fact, when I run your function on test arrays it almost runs perfectly (if it’s a text array, there’s a superfluous 0, that that it matters in this case, but it’s still good to be precise).
test = [5,4,3]
test2 = ['a','b','c']
test3 = [5,5,5]
const sumValues = (test) => Object.keys(test).reduce((acc, value)
=> acc + test[value], 0);
That doesn’t mean it can’t be clarified further:
const sumValues = (obj) => Object.keys(obj).reduce((acc, value)
=> acc + obj[value], 0);
The first observation is your
obj will already have a reduce method, so there is no need to invoke Object.keys (it just makes things more complicated).
The second observation is you can define your function outside of the line for extra clarity (though in a real situation you may have it inside if it’s a throwaway line).
In cases like these it’s very helpful to check MDN documentation for guidance: