Skip to content

Commit 5ca17da

Browse files
committed
Auto-generated commit
1 parent 61f1243 commit 5ca17da

File tree

12 files changed

+935
-14
lines changed

12 files changed

+935
-14
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
### Features
1212

1313
- [`5c5dd63`](https://github.com/stdlib-js/stdlib/commit/5c5dd632d992ce0486d5df295af417435d37579b) - add `object/some-in-by`
14+
- [`27331ac`](https://github.com/stdlib-js/stdlib/commit/27331acd07b701a431a5efd7ccf7104f9be8c5de) - add `object/none-in-by`
1415
- [`9764a3e`](https://github.com/stdlib-js/stdlib/commit/9764a3e691011e9f2d957b51fc0b5766b1df9989) - add `object/every-own-by`
1516
- [`3c99007`](https://github.com/stdlib-js/stdlib/commit/3c99007c615b7df61d85d7d88eca7a19ee4efde4) - add `object/every-in-by`
1617

@@ -25,6 +26,9 @@
2526
<details>
2627

2728
- [`5c5dd63`](https://github.com/stdlib-js/stdlib/commit/5c5dd632d992ce0486d5df295af417435d37579b) - **feat:** add `object/some-in-by` _(by Neeraj Pathak)_
29+
- [`f436338`](https://github.com/stdlib-js/stdlib/commit/f4363380546535eacc2ab3d924ef1d40cafd182b) - **chore:** fix README lint errors _(by Neeraj Pathak)_
30+
- [`47f76c4`](https://github.com/stdlib-js/stdlib/commit/47f76c450e19eb90c7fa2c932b5be286951b0965) - **refactor:** update paths _(by Neeraj Pathak)_
31+
- [`27331ac`](https://github.com/stdlib-js/stdlib/commit/27331acd07b701a431a5efd7ccf7104f9be8c5de) - **feat:** add `object/none-in-by` _(by Neeraj Pathak)_
2832
- [`9764a3e`](https://github.com/stdlib-js/stdlib/commit/9764a3e691011e9f2d957b51fc0b5766b1df9989) - **feat:** add `object/every-own-by` _(by Neeraj Pathak)_
2933
- [`3c99007`](https://github.com/stdlib-js/stdlib/commit/3c99007c615b7df61d85d7d88eca7a19ee4efde4) - **feat:** add `object/every-in-by` _(by Neeraj Pathak)_
3034

every-in-by/README.md

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -122,20 +122,6 @@ bool = everyInBy( o, isPositive );
122122

123123
<section class="related">
124124

125-
<!-- <related-links> -->
126-
127-
[@stdlib/utils/any-in-by]: https://github.com/stdlib-js/utils-any-in-by
128-
129-
[@stdlib/utils/none-in-by]: https://github.com/stdlib-js/utils-none-in-by
130-
131-
[@stdlib/utils/some-in-by]: https://github.com/stdlib-js/utils-some-in-by
132-
133-
[@stdlib/utils/every-by]: https://github.com/stdlib-js/utils-every-by
134-
135-
[@stdlib/utils/every-own-by]: https://github.com/stdlib-js/utils-every-own-by
136-
137-
<!-- </related-links> -->
138-
139125
</section>
140126

141127
<!-- /.links -->

none-in-by/README.md

Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2024 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# noneInBy
22+
23+
> Test whether every property of an object fails a test implemented by a predicate function.
24+
25+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
26+
27+
<section class="intro">
28+
29+
</section>
30+
31+
<!-- /.intro -->
32+
33+
<!-- Package usage documentation. -->
34+
35+
<section class="usage">
36+
37+
## Usage
38+
39+
```javascript
40+
var noneInBy = require( '@stdlib/object/none-in-by' );
41+
```
42+
43+
#### noneInBy( object, predicate\[, thisArg ] )
44+
45+
Tests whether every property of an `object` fails a test implemented by a `predicate` function.
46+
47+
```javascript
48+
function isUnderage( age ) {
49+
return ( age < 18 );
50+
}
51+
52+
var obj = {
53+
'a': 28,
54+
'b': 22,
55+
'c': 25
56+
};
57+
58+
var bool = noneInBy( obj, isUnderage );
59+
// returns true
60+
```
61+
62+
If a `predicate` function returns a truthy value, the function **immediately** returns `false`.
63+
64+
```javascript
65+
function isUnderage( age ) {
66+
return ( age < 18 );
67+
}
68+
69+
var obj = {
70+
'a': 12,
71+
'b': 22,
72+
'c': 25
73+
};
74+
75+
var bool = noneInBy( obj, isUnderage );
76+
// returns false
77+
```
78+
79+
The invoked `function` is provided three agruments:
80+
81+
- **value**: property value.
82+
- **key**: property key.
83+
- **object**: input object.
84+
85+
To set the function execution context, provide a `thisArg`.
86+
87+
```javascript
88+
function sum( value ) {
89+
if ( value < 0 ) {
90+
return true;
91+
}
92+
this.sum += value;
93+
this.count += 1;
94+
return false;
95+
}
96+
97+
var obj = {
98+
'a': 1,
99+
'b': 2,
100+
'c': 3,
101+
'd': 4
102+
};
103+
104+
var context = {
105+
'sum': 0,
106+
'count': 0
107+
};
108+
109+
var bool = noneInBy( obj, sum, context );
110+
// returns true
111+
112+
var mean = context.sum / context.count;
113+
// returns 2.5
114+
```
115+
116+
</section>
117+
118+
<!-- /.usage -->
119+
120+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
121+
122+
<section class="notes">
123+
124+
## Notes
125+
126+
- If the 1st argument is not an object or the second argument is not a function, the
127+
function throws a Type Error.
128+
129+
- If provided an empty object, the function returns `true`.
130+
131+
```javascript
132+
function truthy() {
133+
return true;
134+
}
135+
var bool = noneInBy( {}, truthy );
136+
// returns true
137+
```
138+
139+
- The function does **not** skip `undefined` elements.
140+
141+
<!-- eslint-disable no-sparse-arrays, stdlib/doctest-marker -->
142+
143+
```javascript
144+
function log( value, index ) {
145+
console.log( '%s: %s', index, value );
146+
return false;
147+
}
148+
149+
var obj = {
150+
'a': 1,
151+
'b': NaN,
152+
'c': NaN,
153+
'd': 4
154+
};
155+
156+
var bool = noneInBy( arr, log );
157+
/* =>
158+
0: 1
159+
1: undefined
160+
2: undefined
161+
3: 4
162+
*/
163+
```
164+
165+
</section>
166+
167+
<!-- /.notes -->
168+
169+
<!-- Package usage examples. -->
170+
171+
<section class="examples">
172+
173+
## Examples
174+
175+
<!-- eslint no-undef: "error" -->
176+
177+
```javascript
178+
var noneInBy = require( '@stdlib/object/none-in-by' );
179+
180+
function isUnderage( age ) {
181+
return age < 18;
182+
}
183+
184+
var obj = {
185+
'a': 26,
186+
'b': 20,
187+
'c': 25
188+
};
189+
190+
var bool = noneInBy( obj, isUnderage );
191+
// returns true
192+
```
193+
194+
</section>
195+
196+
<!-- /.examples -->
197+
198+
<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
199+
200+
<section class="references">
201+
202+
</section>
203+
204+
<!-- /.references -->
205+
206+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
207+
208+
<section class="related">
209+
210+
* * *
211+
212+
## See Also
213+
214+
- <span class="package-name">[`@stdlib/utils/any-in-by`][@stdlib/utils/any-in-by]</span><span class="delimiter">: </span><span class="description">test whether at least one property in an object passes a test implemented by a predicate function.</span>
215+
- <span class="package-name">[`@stdlib/object/every-in-by`][@stdlib/object/every-in-by]</span><span class="delimiter">: </span><span class="description">test whether all properties (own and inherited) of an object pass a test implemented by a predicate function.</span>
216+
- <span class="package-name">[`@stdlib/utils/for-in`][@stdlib/utils/for-in]</span><span class="delimiter">: </span><span class="description">invoke a function for each own and inherited enumerable property of an object.</span>
217+
- <span class="package-name">[`@stdlib/utils/none-by`][@stdlib/utils/none-by]</span><span class="delimiter">: </span><span class="description">test whether all elements in a collection fail a test implemented by a predicate function.</span>
218+
- <span class="package-name">[`@stdlib/utils/some-in-by`][@stdlib/utils/some-in-by]</span><span class="delimiter">: </span><span class="description">test whether an object contains at least n properties (own and inherited) which pass a test implemented by a predicate function.</span>
219+
220+
</section>
221+
222+
<!-- /.related -->
223+
224+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
225+
226+
<section class="links">
227+
228+
<!-- <related-links> -->
229+
230+
[@stdlib/utils/any-in-by]: https://github.com/stdlib-js/utils-any-in-by
231+
232+
[@stdlib/object/every-in-by]: https://github.com/stdlib-js/object/tree/main/every-in-by
233+
234+
[@stdlib/utils/for-in]: https://github.com/stdlib-js/utils-for-in
235+
236+
[@stdlib/utils/none-by]: https://github.com/stdlib-js/utils-none-by
237+
238+
[@stdlib/utils/some-in-by]: https://github.com/stdlib-js/utils-some-in-by
239+
240+
<!-- </related-links> -->
241+
242+
</section>
243+
244+
<!-- /.links -->

none-in-by/benchmark/benchmark.js

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
25+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
26+
var pkg = require( './../package.json' ).name;
27+
var noneInBy = require( './../lib' );
28+
29+
30+
// MAIN //
31+
32+
bench( pkg, function benchmark( b ) {
33+
var bool;
34+
var obj;
35+
var i;
36+
37+
function predicate( v ) {
38+
return isnan( v );
39+
}
40+
41+
b.tic();
42+
for ( i = 0; i < b.iterations; i++ ) {
43+
obj = {
44+
'a': i,
45+
'b': i + 1,
46+
'c': i + 2,
47+
'd': i + 3,
48+
'e': i + 4
49+
};
50+
bool = noneInBy( obj, predicate );
51+
if ( typeof bool !== 'boolean' ) {
52+
b.fail( 'should return a boolean' );
53+
}
54+
}
55+
b.toc();
56+
if ( !isBoolean( bool ) ) {
57+
b.fail( 'should return a boolean' );
58+
}
59+
b.pass( 'benchmark finished' );
60+
b.end();
61+
});
62+
63+
bench( pkg+'::for-in-loop', function benchmark( b ) {
64+
var bool;
65+
var obj;
66+
var key;
67+
var i;
68+
69+
b.tic();
70+
for ( i = 0; i < b.iterations; i++ ) {
71+
obj = {
72+
'a': i,
73+
'b': i + 1,
74+
'c': i + 2,
75+
'd': i + 3,
76+
'e': i + 4
77+
};
78+
bool = true;
79+
for ( key in obj ) {
80+
if ( isnan( obj[key] ) ) {
81+
bool = false;
82+
break;
83+
}
84+
}
85+
if ( typeof bool !== 'boolean' ) {
86+
b.fail( 'should return a boolean' );
87+
}
88+
}
89+
b.toc();
90+
if ( !isBoolean( bool ) ) {
91+
b.fail( 'should return a boolean' );
92+
}
93+
b.pass( 'benchmark finished' );
94+
b.end();
95+
});

0 commit comments

Comments
 (0)