score:1

your input to _.reduce is just level1.test[teststate.id], which seems to be a non-array object. nothing in that code tells _.reduce it would work on the .p1.o1, .p1.o2, and .p1.o3 properties on the object.

if you want to use reduce for this, i'd use the native one and start with an array of property names:

checker2 = ['o1', 'o2', 'o3'].reduce(
    (checker, prop) => checker && level1.test[teststate.id].p1 === undefined,
    false
);

... in a optimized and less code

reduce doesn't do either of those things. it requires creating an array and multiple function calls. instead:

const obj = level1.test[teststate.id].p1;
checker = obj.o1 === undefined && obj.o2 === undefined && obj.o3 === undefined;

(if you are going to use an array and callbacks, use every as akx points out.)

score:4

it'd be easier (and more performant, as it has early-exit properties) to use array.every:

const obj = level1.test[teststate.id].p1;
const checker1 = ['o1', 'o2', 'o3'].every(key => obj[key] === undefined);

Related Query

More Query from same tag