0

I do not get it why false is returned, am I missing something here?

const validInputs = (...inputs) => {
  const check = inputs.every(inp => {
    Number.isFinite(inp);
  });
  return check;
};

console.log(validInputs([1, 2, 3, 4, 5]));
G-T
  • 111
  • 6
  • Your `every` callback never returns anything, which basically means it always returns `undefined`, which is falsy. – T.J. Crowder May 01 '21 at 10:58
  • Watching a JS course and an instructor wrote the exact same code without returning anything in every callback, his code returns true, and mine false, what should I return explicitly though, true? – G-T May 01 '21 at 11:06

1 Answers1

0

There are 2 issues, the callback isn't returning anything and you shouldn't rest the array((...input)) as this will make inputs an array of array.

const validInputs = (inputs) => {
  const check = inputs.every(inp => {
    return Number.isFinite(inp);
  });
  return check;
};

console.log(validInputs([1, 2, 3, 4, 5]));
Ramesh Reddy
  • 10,159
  • 3
  • 17
  • 32
  • 1
    Ah I am watching a course, he wrote a callback without {} and totally forgot it includes return keyword automatically, also called a function without without [], thank you. – G-T May 01 '21 at 11:15