-
-
Notifications
You must be signed in to change notification settings - Fork 804
[RFC]: Add @stdlib/utils/every-in-by
#822
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
Comments
would you explain this more i am not able to understand this? |
By example, function predicate( value, key, obj ) {
return ( value > 0 );
}
var o = {
'a': 1,
'b': 2,
'c': 3,
'd': 4
};
var bool = everyInBy( o, predicate );
// returns true
o.a = -2;
bool = everyInBy( o, predicate );
// returns false Pay attention to the OP. Namely, it should also work for inherited properties. |
i have created this test function will this work or should i make changes? function predicate( value, key, obj ) {
return ( value > 0 );
}
function everyByIn(obj, predicate, thisArg) {
var out
if ( !isObject( obj ) ) {
throw new TypeError( format( 'invalid argument. First argument must be a object. Value: `%s`.', obj ) );
}
if ( !isFunction( predicate ) ) {
throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', predicate ) );
}
for (const key in obj) {
if (obj.hasOwnProperty(key)) {
out = predicate.call(thisArg, obj[key], key, obj)
if (!out) {
return false
}
}
}
return true
} |
You don't want the |
You can also inline the |
Otherwise, yes, what you have proposed is a good start. Feel free to open a PR with the implementation and associated package files. @Planeshifter Should we go ahead and rename the package to |
cool i am excited on this one i will make changes regarding to it. then comment it before making a PR. |
Sounds good! Thanks for working on it! |
no worries happy to contribute. |
here is the updated function. function everyByIn(obj, predicate, thisArg) {
var key
if (!isObject(obj)) {
throw new TypeError(format('invalid argument. First argument must be an object. Value: `%s`.', obj));
}
if (!isFunction(predicate)) {
throw new TypeError(format('invalid argument. Second argument must be a function. Value: `%s`.', predicate));
}
// Use a for...in loop to iterate through all enumerable properties, including inherited ones
for (key in obj) {
if (!predicate.call(thisArg, obj[key], key, obj)) {
return false;
}
}
return true;
} |
everything is working fine locally. |
That looks reasonable. Note that we author everything in ES5, so no |
i have updated the comment code. |
from next time i will keep that in my mind. |
shall i make a PR now or wait. |
Go ahead and open a PR. |
You'll obviously need to add docs, tests, and benchmarks similar to other packages. |
ok, i will make PR by tonight. |
PR-URL: #1409 Closes: #822 --------- Signed-off-by: Philipp Burckhardt <[email protected]> Co-authored-by: Philipp Burckhardt <[email protected]> Reviewed-by: Philipp Burckhardt <[email protected]>
Description
This RFC proposes adding a utility to test whether every "own" and inherited property of a provided object satisfies a predicate function.
This is the
for-in
equivalent of@stdlib/utils/every-by
.Package:
@stdlib/utils/every-in-by
Alias:
everyInBy
Related Issues
None.
Questions
No.
Other
No.
Checklist
RFC:
.The text was updated successfully, but these errors were encountered: