docs(negate): add missing example (#504)
Some checks are pending
CI / codecov (push) Waiting to run
Release / release (push) Waiting to run

Co-authored-by: Sojin Park <raon0211@toss.im>
This commit is contained in:
Junseong Park 2024-09-10 08:41:32 +09:00 committed by GitHub
parent eb8bf63ad7
commit f36282a35a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -4,6 +4,12 @@
* @template F - The type of the function to negate.
* @param {F} func - The function to negate.
* @returns {F} The new negated function, which negates the boolean result of `func`.
*
* @example
* const array = [1, 2, 3, 4, 5, 6];
* const isEven = (n: number) => n % 2 === 0;
* const result = array.filter(negate(isEven));
* // result will be [1, 3, 5]
*/
export function negate<F extends (...args: any[]) => boolean>(func: F): F {
return ((...args: any[]) => !func(...args)) as F;