Skip to content

Commit 05a7e9f

Browse files
committed
Auto-generated commit
1 parent 791f608 commit 05a7e9f

13 files changed

Lines changed: 946 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
55
<section class="release" id="unreleased">
66

7-
## Unreleased (2025-11-10)
7+
## Unreleased (2025-11-29)
88

99
<section class="features">
1010

1111
### Features
1212

13+
- [`4ebdf6c`](https://github.com/stdlib-js/stdlib/commit/4ebdf6c5b911d2bfde819ab56e654a22b9f85133) - add `object/any-in-by`
1314
- [`0c6de9f`](https://github.com/stdlib-js/stdlib/commit/0c6de9f46e489bf4d7a9f3899dbe963348fc7480) - update `object` TypeScript declarations
1415
- [`ccb87b6`](https://github.com/stdlib-js/stdlib/commit/ccb87b67fc9b58a37d5603ee1b86658bc70f0ef3) - add missing exports to namespaces
1516
- [`a2d3800`](https://github.com/stdlib-js/stdlib/commit/a2d3800b4450759ff17f368e1c274e650eab15fe) - add `assignIn` to namespace
@@ -29,6 +30,9 @@
2930

3031
<details>
3132

33+
- [`f03b259`](https://github.com/stdlib-js/stdlib/commit/f03b259e592ffe69c5c59f9f2d2a4a2cba508244) - **docs:** fix missing sections _(by Athan Reines)_
34+
- [`6ea3fff`](https://github.com/stdlib-js/stdlib/commit/6ea3fff1850167852dc0ea18003c1e0209d70335) - **refactor:** update paths _(by Neeraj Pathak)_
35+
- [`4ebdf6c`](https://github.com/stdlib-js/stdlib/commit/4ebdf6c5b911d2bfde819ab56e654a22b9f85133) - **feat:** add `object/any-in-by` _(by Neeraj Pathak)_
3236
- [`7849e6f`](https://github.com/stdlib-js/stdlib/commit/7849e6ffba5b1734a5314c5ded28602dd75e0f3c) - **style:** remove semicolons after function declarations _(by Philipp Burckhardt)_
3337
- [`5f5bb2d`](https://github.com/stdlib-js/stdlib/commit/5f5bb2d4277a24000b57fb07bc28d821500cd7e8) - **docs:** update namespace table of contents [(#8425)](https://github.com/stdlib-js/stdlib/pull/8425) _(by stdlib-bot, Athan Reines)_
3438
- [`0c6de9f`](https://github.com/stdlib-js/stdlib/commit/0c6de9f46e489bf4d7a9f3899dbe963348fc7480) - **feat:** update `object` TypeScript declarations _(by Philipp Burckhardt)_

any-in-by/README.md

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
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+
# anyInBy
22+
23+
> Test whether at least one property in an object passes 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 anyInBy = require( '@stdlib/object/any-in-by' );
41+
```
42+
43+
#### anyInBy( object, predicate\[, thisArg ] )
44+
45+
Tests whether at least one property in an `object` passes a test implemented by a `predicate` function.
46+
47+
```javascript
48+
function isNegative( value ) {
49+
return ( value < 0 );
50+
}
51+
52+
var obj = {
53+
'a': 1,
54+
'b': 2,
55+
'c': -1
56+
};
57+
58+
var bool = anyInBy( obj, isNegative );
59+
// returns true
60+
```
61+
62+
If a `predicate` function returns a truthy value, the function **immediately** returns `true`.
63+
64+
```javascript
65+
function isPositive( value ) {
66+
if ( value < 0 ) {
67+
throw new Error( 'should never reach this line' );
68+
}
69+
return ( value > 0 );
70+
}
71+
72+
var obj = {
73+
'a': 1,
74+
'b': -2,
75+
'c': 3
76+
};
77+
78+
var bool = anyInBy( obj, isPositive );
79+
// returns true
80+
```
81+
82+
The invoked `function` is provided three arguments:
83+
84+
- **value**: property value.
85+
- **key**: property key.
86+
- **object**: input object.
87+
88+
To set the function execution context, provide a `thisArg`.
89+
90+
```javascript
91+
function sum( value ) {
92+
this.sum += value;
93+
this.count += 1;
94+
return ( value < 0 );
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 = anyInBy( obj, sum, context );
110+
// returns true
111+
112+
var mean = context.sum / context.count;
113+
// returns 0.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+
- The `obj` object may contain own properties as well as inherited properties from its prototype chain.
127+
128+
- If provided an empty object, the function returns `false`.
129+
130+
```javascript
131+
function alwaysTrue() {
132+
return true;
133+
}
134+
var bool = anyInBy( {}, alwaysTrue );
135+
// returns false
136+
```
137+
138+
</section>
139+
140+
<!-- /.notes -->
141+
142+
<!-- Package usage examples. -->
143+
144+
<section class="examples">
145+
146+
## Examples
147+
148+
<!-- eslint no-undef: "error" -->
149+
150+
```javascript
151+
var randu = require( '@stdlib/random/base/randu' );
152+
var anyInBy = require( '@stdlib/object/any-in-by' );
153+
154+
function threshold( value ) {
155+
return ( value > 0.95 );
156+
}
157+
158+
var bool;
159+
var obj = {};
160+
var i;
161+
162+
for ( i = 0; i < 100; i++ ) {
163+
obj[i] = randu();
164+
}
165+
166+
bool = anyInBy( obj, threshold );
167+
// returns <boolean>
168+
```
169+
170+
</section>
171+
172+
<!-- /.examples -->
173+
174+
<!-- 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. -->
175+
176+
<section class="references">
177+
178+
</section>
179+
180+
<!-- /.references -->
181+
182+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
183+
184+
<section class="related">
185+
186+
</section>
187+
188+
<!-- /.related -->
189+
190+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
191+
192+
<section class="links">
193+
194+
</section>
195+
196+
<!-- /.links -->

any-in-by/benchmark/benchmark.js

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
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 anyInBy = 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+
'f': NaN
50+
};
51+
bool = anyInBy( obj, predicate );
52+
if ( typeof bool !== 'boolean' ) {
53+
b.fail( 'should return a boolean' );
54+
}
55+
}
56+
b.toc();
57+
if ( !isBoolean( bool ) ) {
58+
b.fail( 'should return a boolean' );
59+
}
60+
b.pass( 'benchmark finished' );
61+
b.end();
62+
});
63+
64+
bench( pkg+'::built-in', function benchmark( b ) {
65+
var bool;
66+
var keys;
67+
var obj;
68+
var i;
69+
70+
function predicate( v ) {
71+
return isnan( v );
72+
}
73+
function testPredicate( key ) {
74+
return predicate( obj[ key ] );
75+
}
76+
77+
b.tic();
78+
for ( i = 0; i < b.iterations; i++ ) {
79+
obj = {
80+
'a': i,
81+
'b': i+1,
82+
'c': i+2,
83+
'd': i+3,
84+
'e': i+4,
85+
'f': NaN
86+
};
87+
keys = Object.keys( obj );
88+
bool = keys.some( testPredicate );
89+
if ( typeof bool !== 'boolean' ) {
90+
b.fail( 'should return a boolean' );
91+
}
92+
}
93+
b.toc();
94+
if ( !isBoolean( bool ) ) {
95+
b.fail( 'should return a boolean' );
96+
}
97+
b.pass( 'benchmark finished' );
98+
b.end();
99+
});
100+
101+
bench( pkg+'::loop', function benchmark( b ) {
102+
var bool;
103+
var keys;
104+
var obj;
105+
var i;
106+
var j;
107+
108+
b.tic();
109+
for ( i = 0; i < b.iterations; i++ ) {
110+
obj = {
111+
'a': i,
112+
'b': i+1,
113+
'c': i+2,
114+
'd': i+3,
115+
'e': i+4,
116+
'f': NaN
117+
};
118+
keys = Object.keys( obj );
119+
bool = false;
120+
for ( j = 0; j < keys.length; j++ ) {
121+
if ( isnan( obj[ keys[j] ] ) ) {
122+
bool = true;
123+
break;
124+
}
125+
}
126+
if ( typeof bool !== 'boolean' ) {
127+
b.fail( 'should return a boolean' );
128+
}
129+
}
130+
b.toc();
131+
if ( !isBoolean( bool ) ) {
132+
b.fail( 'should be a boolean' );
133+
}
134+
b.pass( 'benchmark finished' );
135+
b.end();
136+
});

0 commit comments

Comments
 (0)