Skip to content

Commit 4814ac9

Browse files
committedJan 2, 2025
Add solution #2618
1 parent 91ef683 commit 4814ac9

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed
 

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@
361361
2490|[Circular Sentence](./2490-circular-sentence.js)|Easy|
362362
2529|[Maximum Count of Positive Integer and Negative Integer](./2529-maximum-count-of-positive-integer-and-negative-integer.js)|Easy|
363363
2535|[Difference Between Element Sum and Digit Sum of an Array](./2535-difference-between-element-sum-and-digit-sum-of-an-array.js)|Easy|
364+
2618|[Check if Object Instance of Class](./2618-check-if-object-instance-of-class.js)|Medium|
364365
3392|[Count Subarrays of Length Three With a Condition](./3392-count-subarrays-of-length-three-with-a-condition.js)|Easy|
365366
3396|[Minimum Number of Operations to Make Elements in Array Distinct](./3396-minimum-number-of-operations-to-make-elements-in-array-distinct.js)|Easy|
366367
3397|[Maximum Number of Distinct Elements After Operations](./3397-maximum-number-of-distinct-elements-after-operations.js)|Medium|
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* 2618. Check if Object Instance of Class
3+
* https://leetcode.com/problems/check-if-object-instance-of-class/
4+
* Difficulty: Medium
5+
*
6+
* Write a function that checks if a given value is an instance of a given class or superclass.
7+
* For this problem, an object is considered an instance of a given class if that object has
8+
* access to that class's methods.
9+
*
10+
* There are no constraints on the data types that can be passed to the function. For example,
11+
* the value or the class could be undefined.
12+
*/
13+
14+
/**
15+
* @param {*} obj
16+
* @param {*} classFunction
17+
* @return {boolean}
18+
*/
19+
var checkIfInstanceOf = function(obj, classFunction) {
20+
if (obj === null || obj === undefined || typeof classFunction !== 'function') {
21+
return false;
22+
}
23+
return Object(obj) instanceof classFunction;
24+
};

0 commit comments

Comments
 (0)
Please sign in to comment.