-
-
Notifications
You must be signed in to change notification settings - Fork 564
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add assert/has-same-constructor
#1357
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👋 Hi there! 👋
And thank you for opening your first pull request! We will review it shortly. 🏃 💨
assert/has-same-constructor
var isArrayLikeObject = require( '@stdlib/assert/has-same-constructor' ); | ||
``` | ||
|
||
#### hasSameConstructor( value , value ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#### hasSameConstructor( value , value ) | |
#### hasSameConstructor( v1, v2 ) |
|
||
var DateObject1 = new Date(); | ||
var DateObject2 = new Date(); | ||
var StringObject = new String("Hello"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using the String
constructor, I suggest use more common examples. E.g., comparing a generic array [ 1, 2, 3 ]
, with a typed array instance (e.g., new Int32Array( [ 1, 2, 3 ] )
). You can also use stdlib classes, such as @stdlib/complex/float64
and @stdlib/complex/float32
.
// => false | ||
``` | ||
|
||
</section> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You removed trailing sections for links, related packages, etc. Please append those here. We use them in various build processes, even if they are empty.
obj2 = new Date(); | ||
obj3 = new String( "Hello" ); | ||
obj4 = "World"; | ||
bool = hasSameConstructor( obj1, obj2 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not what we want. Please see other benchmarks for how we measure things and read the benchmark harness README to get a better understanding of how benchmarks should be written: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/bench/harness.
/** | ||
* Benchmark the hasSameConstructor function when provided with same value types. | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for JSDoc comments here and below.
|
||
#### hasSameConstructor( v1, v2 ) | ||
|
||
Tests if two values have same constructor. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests if two values have same constructor. | |
Tests if two values have the same constructor. |
// returns true | ||
|
||
var obj1 = new Date(); | ||
var obj3 = new String("Hello"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var obj3 = new String("Hello"); | |
var obj3 = new String( 'Hello' ); |
As elsewhere in this project, spaces and we use single quotes. Here and everywhere else.
|
||
</section> | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<!-- eslint-disable no-new-wrappers --> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<!-- eslint-disable no-new-wrappers --> |
var ComplexObj = new Complex64( 5.0, 3.0 ); | ||
|
||
var bool = hasSameConstructor( DateObj1, DateObj2 ); | ||
// => true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not how we do doctesting. See our doctesting guide: https://github.com/stdlib-js/stdlib/blob/develop/docs/doctest.md
|
||
* * * | ||
|
||
## See Also | ||
|
||
- <span class="package-name">[`@stdlib/assert/has-iterator-symbol-support`][@stdlib/assert/has-iterator-symbol-support]</span><span class="delimiter">: </span><span class="description">detect native Symbol.iterator support.</span> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* * * | |
## See Also | |
- <span class="package-name">[`@stdlib/assert/has-iterator-symbol-support`][@stdlib/assert/has-iterator-symbol-support]</span><span class="delimiter">: </span><span class="description">detect native Symbol.iterator support.</span> |
<!-- <related-links> --> | ||
|
||
[@stdlib/assert/has-iterator-symbol-support]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/assert/has-iterator-symbol-support | ||
|
||
<!-- </related-links> --> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<!-- <related-links> --> | |
[@stdlib/assert/has-iterator-symbol-support]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/assert/has-iterator-symbol-support | |
<!-- </related-links> --> |
var pkg = require( './../package.json' ).name; | ||
var hasSameConstructor = require( './../lib' ); | ||
|
||
// MAIN // |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// MAIN // | |
// MAIN // |
If provided with two values with different constructors, the function returns `false`. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If provided with two values with different constructors, the function returns `false`. |
@@ -0,0 +1,35 @@ | |||
{{alias}}( value ) | |||
Tests if two values have same constructor. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests if two values have same constructor. | |
Tests if two values have the same constructor. |
Here and elsewhere.
|
||
Examples | ||
-------- | ||
> var obj1 = new Date(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not how we do examples. See https://github.com/stdlib-js/stdlib/blob/develop/docs/repl_text.md.
/** | ||
* Test whether two provided values have the same constructor. | ||
* | ||
* @param {*} a - The first value to test. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't include type annotations in our TypeScript JSDoc comments. And also, this is not the format we use for parameter descriptions. Please refer to other packages for examples.
* | ||
* @param {*} a - The first value to test. | ||
* @param {*} b - The second value to test. | ||
* @returns {boolean} Returns `true` if both values have the same constructor, else `false`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @returns {boolean} Returns `true` if both values have the same constructor, else `false`. | |
* @returns boolean indicating whether two values have the same constructor |
* @param {*} a - The first value to test. | ||
* @param {*} b - The second value to test. | ||
* @returns {boolean} Returns `true` if both values have the same constructor, else `false`. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* |
* var bool = hasSameConstructor(obj3, obj4); | ||
* // returns true | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* // returns true | ||
*/ | ||
|
||
declare function hasSameConstructor(a: any, b: any): boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
declare function hasSameConstructor(a: any, b: any): boolean; | |
declare function hasSameConstructor( a: any, b: any ): boolean; |
* limitations under the License. | ||
*/ | ||
|
||
import hasSameConstructor from './index'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import hasSameConstructor from './index'; | |
import hasSameConstructor = require( './index' ); | |
Please follow practices observed in other packages.
|
||
// The function returns a boolean... | ||
{ | ||
hasSameConstructor(new Date(), new String("Hello")); // $ExpectType boolean |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spaces. Quotes.
'use strict'; | ||
|
||
var hasSameConstructor = require( './../lib' ); | ||
var Float64Array = require( '@stdlib/array/float64' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Require statement order.
* @param {*} a - The first value to test. | ||
* @param {*} b - The second value to test. | ||
* @returns {boolean} Returns `true` if both values have the same constructor, else `false`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please follow conventions used in the project
* var bool = hasSameConstructor(obj3, obj4); | ||
* // returns true | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* // returns true | ||
*/ | ||
|
||
function hasSameConstructor(a, b) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function hasSameConstructor(a, b) { | |
function hasSameConstructor( a, b ) { |
return a && b && a.constructor === b.constructor; | ||
} | ||
|
||
module.exports = hasSameConstructor; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing // EXPORTS //
heading.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kaushiktak19 I suggest studying other packages in the project and trying to align your contribution as closely as possible to what is currently in the project.
assert/has-same-constructor
assert/has-same-constructor
This pull request has been automatically closed because it has been inactive for an extended period after changes were requested. If you still wish to pursue this contribution, feel free to reopen the pull request or submit a new one. We appreciate your interest in contributing to stdlib! |
Resolves #815
Description
This pull request:
@stdlib/assert/has-same-constructor
.Related Issues
This pull request:
@stdlib/assert/has-same-constructor
#815 .Questions
No.
Other
No.
Checklist
@stdlib-js/reviewers