October 17th, 2024
What's missing in this code?
func('5-3', ['true', 'true', 'true']); // 6
func('8-2', ['false', 'false', 'false']); // 0
func('10-4', ['true', 'false', 'true', 'true']); // 18
func('100-0', ['true', 'true']); // 200
func('9-3', ['false', 'true', 'false']); // 6
func('12-6', []); // 0
function func(str, boolArray) {
const [num1, num2] = str.
('-').
(Number);
const diff = Math.abs(num1 - num2);
const count = boolArray.reduce(
(count, val) => count + (
? 1 : 0),
0
);
return diff * count;
}
Type or select from these options