-1

Here is a function which accepts 'value' and returns a true and false based on the fact its number or not. But it accepts '1....2' too and returns true which is a problem. I am confused on how to deal with it.

const boolean = (value, schema) => {
return (
    value === false ||
    value === true ||
    value === "true" ||
    value === "false" ||
    value === "0" ||
    value === "1"
);
};

const float = (value, schema) => {
    return !isNaN(parseFloat(value));
};
3
  • Tried using 'lodash-contrib'. Got confused during implementation. Jan 29 at 22:46
  • "it accepts '1....2' too and returns true" - no it doesn't, boolean('1....2') is false?
    – Bergi
    Jan 29 at 22:47
  • What's the purpose of the schema parameter?
    – Bergi
    Jan 29 at 22:49

1 Answer 1

0

this worked. without using lodash-contrib

const float = (value, schema) => {
return !isNaN(parseFloat(value)) && isFinite(value); };

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.