Created
November 26, 2019 11:00
-
-
Save eliah-w/b34dc854cdde4fd9d9b9087cdf03b75b to your computer and use it in GitHub Desktop.
Array.prototype.onlySome - Determines whether some but not all members of an array satisfy the specified test.
This file contains hidden or 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
/** | |
* Determines whether some but not all members of an array satisfy the specified test. | |
* | |
* @param callbackfn A function that accepts up to three arguments. The onlySome method calls | |
* Array.prototype.some and Array.prototype.every. Both call the callbackfn function for each | |
* element in the array until the callbackfn returns a value which is coercible to the Boolean value true | |
* or false respectively, or until the end of the array. | |
* @param thisArg An object to which the this keyword can refer in the callbackfn function. | |
* If thisArg is omitted, undefined is used as the this value. | |
* @returns {boolean} | |
*/ | |
Array.prototype.onlySome = function(callbackfn, thisArg = undefined) { | |
if (this === null) { | |
throw new TypeError("Array.prototype.onlySome called on null or undefined"); | |
} | |
return !this.every(callbackfn, thisArg) && this.some(callbackfn, thisArg); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment