-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
is-shallow-equal: Fall back to strict equality for non-object-like (#116
) * Ensure inverse argument order has same test result * is-shallow-equal: Fall back to strict equality for non-object-like * is-shallow-equal: De-snark README.md
- Loading branch information
Showing
6 changed files
with
168 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,31 @@ | ||
module.exports = require( './' ).isShallowEqualArrays; | ||
'use strict'; | ||
|
||
/** | ||
* Returns true if the two arrays are shallow equal, or false otherwise. | ||
* | ||
* @param {Array} a First array to compare. | ||
* @param {Array} b Second array to compare. | ||
* | ||
* @return {Boolean} Whether the two arrays are shallow equal. | ||
*/ | ||
function isShallowEqualArrays( a, b ) { | ||
var i; | ||
|
||
if ( a === b ) { | ||
return true; | ||
} | ||
|
||
if ( a.length !== b.length ) { | ||
return false; | ||
} | ||
|
||
for ( i = 0; i < a.length; i++ ) { | ||
if ( a[ i ] !== b[ i ] ) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
module.exports = isShallowEqualArrays; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,41 @@ | ||
module.exports = require( './' ).isShallowEqualObjects; | ||
'use strict'; | ||
|
||
var keys = Object.keys; | ||
|
||
/** | ||
* Returns true if the two objects are shallow equal, or false otherwise. | ||
* | ||
* @param {Object} a First object to compare. | ||
* @param {Object} b Second object to compare. | ||
* | ||
* @return {Boolean} Whether the two objects are shallow equal. | ||
*/ | ||
function isShallowEqualObjects( a, b ) { | ||
var aKeys, bKeys, i, key; | ||
|
||
if ( a === b ) { | ||
return true; | ||
} | ||
|
||
aKeys = keys( a ); | ||
bKeys = keys( b ); | ||
|
||
if ( aKeys.length !== bKeys.length ) { | ||
return false; | ||
} | ||
|
||
i = 0; | ||
|
||
while ( i < aKeys.length ) { | ||
key = aKeys[ i ]; | ||
if ( a[ key ] !== b[ key ] ) { | ||
return false; | ||
} | ||
|
||
i++; | ||
} | ||
|
||
return true; | ||
}; | ||
|
||
module.exports = isShallowEqualObjects; |
Oops, something went wrong.