Skip to content

Variadic is binary function. #49

Open

Description

@jhowardjr

Help requested to create a variadic isBinary function that returns true if all the numbers in the parameter list are binary.

Activity

  1. self-assigned this
    on Feb 7, 2018
  2. snuxy-pk commented on Mar 17, 2018

    @snuxy-pk
    Contributor

    Alright so I need a few suggestions on this one guys:

    here is my code so far:
    image

    My issue is after running this test:
    image

    I get this failure:
    image

    So I decided to do some manual tests to see what I get:
    image

    Acording to regExr everything matches:
    image
    So I can understand that .test() method will convert a number to a string if its not a string already, so 0110 is converted to 72 as the .toString() method on the regex prototype defaults the conversion to base 10 then it returns true cause 72 doesn't contain a 0 or 1. I can easily just make sure to convert the number to a binary string manually by using a param of 2 (binary radix), then have it do the regex test. But obviously we can not do this with every param passed in or then it will convert non-binary numbers to binary numbers, defeating well the purpose of the function.

    I am also receiving this lint error:
    image
    This doesn't make sense cause Number.isNaN(0110) // false.

    Should I string split any zeros out before its tested? Should I have a way to catch the binary representation of a number and return true instead of having it run through the regex .test() method?

    Thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

help wantedExtra attention is needed

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions