+
Skip to content

"is.Number" is accepting Arrays with numbers and string numbers #41

@brunocasanova

Description

@brunocasanova

In my project i've found two strange cases with is.Number function, that i think that's not behaving like it should.

I have a condition like the example underneath, that only accept Numbers, but in fact is.Number is accepting arrays with numbers or string numbers. I don't think this is the right behavior to handle it, unless it have a good reason for that, that i'm not seeing clearly.

var Util = require( 'findhit-util' );

var array1 = [ "123" ];
var array2 = [ 123 ];

// Example 1
if( Util.is.Number( array1 ) ){
   console.log( "array1 it's a number..."  );
}else{
   console.log( "array1 it's not a number..."  );
}

// Example 2
if( Util.is.Number( array2 ) ){
   console.log( "array2 it's a number..." );
}else{
   console.log( "array2 it's not a number..." );
}

// example 1 console.log -> "array1 it's a number..."
// example 2 console.log -> "array2 it's a number..."

// the cases above should not be a number...

And the Same ( opposite ) thing for isnt.Number:

// Example 3
if( Util.isnt.Number( array1 ) ){
   console.log( "array1 it's not a number..." );
}else{
   console.log( "array1 it's a number..." );
}

// Example 4
if( Util.isnt.Number( array2 ) ){
   console.log( "array2 it's not a number..." );
}else{
   console.log( "array2 it's a number..." );
}

// example 3 console.log -> "array1 it's a number..."
// example 4 console.log -> "array2 it's a number..."

// the cases above should not be a number...

Maybe the proto of the array is assuming the number since the array contains it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载