@stdlib/array-base-count-ifs 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +177 -0
- package/NOTICE +1 -0
- package/README.md +248 -0
- package/SECURITY.md +5 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +7 -0
- package/docs/types/index.d.ts +243 -0
- package/lib/index.js +51 -0
- package/lib/main.js +175 -0
- package/package.json +68 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
package/NOTICE
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Copyright (c) 2016-2026 The Stdlib Authors.
|
package/README.md
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
|
|
3
|
+
@license Apache-2.0
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2025 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
|
+
|
|
22
|
+
<details>
|
|
23
|
+
<summary>
|
|
24
|
+
About stdlib...
|
|
25
|
+
</summary>
|
|
26
|
+
<p>We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.</p>
|
|
27
|
+
<p>The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.</p>
|
|
28
|
+
<p>When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.</p>
|
|
29
|
+
<p>To join us in bringing numerical computing to the web, get started by checking us out on <a href="https://github.com/stdlib-js/stdlib">GitHub</a>, and please consider <a href="https://opencollective.com/stdlib">financially supporting stdlib</a>. We greatly appreciate your continued support!</p>
|
|
30
|
+
</details>
|
|
31
|
+
|
|
32
|
+
# countIfs
|
|
33
|
+
|
|
34
|
+
[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] <!-- [![dependencies][dependencies-image]][dependencies-url] -->
|
|
35
|
+
|
|
36
|
+
> Perform element-wise evaluation of one or more input arrays according to provided predicate functions and count the number of elements for which all predicates respectively return `true`.
|
|
37
|
+
|
|
38
|
+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
|
|
39
|
+
|
|
40
|
+
<section class="intro">
|
|
41
|
+
|
|
42
|
+
</section>
|
|
43
|
+
|
|
44
|
+
<!-- /.intro -->
|
|
45
|
+
|
|
46
|
+
<!-- Package usage documentation. -->
|
|
47
|
+
|
|
48
|
+
<section class="installation">
|
|
49
|
+
|
|
50
|
+
## Installation
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
npm install @stdlib/array-base-count-ifs
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
</section>
|
|
57
|
+
|
|
58
|
+
<section class="usage">
|
|
59
|
+
|
|
60
|
+
## Usage
|
|
61
|
+
|
|
62
|
+
```javascript
|
|
63
|
+
var countIfs = require( '@stdlib/array-base-count-ifs' );
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
#### countIfs( x0, predicate0\[, x1, predicate1\[, x2, predicate2\[, ...args]]] )
|
|
67
|
+
|
|
68
|
+
Performs element-wise evaluation of one or more input arrays according to provided predicate functions and counts the number of elements for which all predicates respectively return `true`.
|
|
69
|
+
|
|
70
|
+
```javascript
|
|
71
|
+
function predicate0( value ) {
|
|
72
|
+
return ( value > 0 );
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function predicate1( value ) {
|
|
76
|
+
return ( value < 3 );
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
var x0 = [ 0, 1, 0, 1, 2 ];
|
|
80
|
+
var x1 = [ 2, 3, 1, 2, 5 ];
|
|
81
|
+
|
|
82
|
+
var out = countIfs( x0, predicate0, x1, predicate1 );
|
|
83
|
+
// returns 1
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
The function has the following parameters:
|
|
87
|
+
|
|
88
|
+
- **x0**: first input array.
|
|
89
|
+
- **predicate0**: first predicate function.
|
|
90
|
+
- **x1**: second input array (_optional_).
|
|
91
|
+
- **predicate1**: second predicate function (_optional_).
|
|
92
|
+
- **x2**: third input array (_optional_).
|
|
93
|
+
- **predicate2**: third predicate function (_optional_).
|
|
94
|
+
- **args**: additional input arrays and corresponding predicate functions (_optional_).
|
|
95
|
+
|
|
96
|
+
Each predicate function is provided three arguments:
|
|
97
|
+
|
|
98
|
+
- **value**: current array element.
|
|
99
|
+
- **index**: current array element index.
|
|
100
|
+
- **arr**: the corresponding input array.
|
|
101
|
+
|
|
102
|
+
</section>
|
|
103
|
+
|
|
104
|
+
<!-- /.usage -->
|
|
105
|
+
|
|
106
|
+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
107
|
+
|
|
108
|
+
<section class="notes">
|
|
109
|
+
|
|
110
|
+
## Notes
|
|
111
|
+
|
|
112
|
+
- The function assumes that all input arrays have the same length.
|
|
113
|
+
- The function supports array-like objects supporting the accessor protocol (e.g., [`Complex128Array`][@stdlib/array/complex128], [`Complex64Array`][@stdlib/array/complex64], etc).
|
|
114
|
+
|
|
115
|
+
</section>
|
|
116
|
+
|
|
117
|
+
<!-- /.notes -->
|
|
118
|
+
|
|
119
|
+
<!-- Package usage examples. -->
|
|
120
|
+
|
|
121
|
+
<section class="examples">
|
|
122
|
+
|
|
123
|
+
## Examples
|
|
124
|
+
|
|
125
|
+
<!-- eslint no-undef: "error" -->
|
|
126
|
+
|
|
127
|
+
<!-- eslint-disable max-len -->
|
|
128
|
+
|
|
129
|
+
```javascript
|
|
130
|
+
var discreteUniform = require( '@stdlib/random-array-discrete-uniform' );
|
|
131
|
+
var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ).isPrimitive;
|
|
132
|
+
var isNegativeInteger = require( '@stdlib/assert-is-negative-integer' ).isPrimitive;
|
|
133
|
+
var naryFunction = require( '@stdlib/utils-nary-function' );
|
|
134
|
+
var countIfs = require( '@stdlib/array-base-count-ifs' );
|
|
135
|
+
|
|
136
|
+
var x = discreteUniform( 10, -5, 5, {
|
|
137
|
+
'dtype': 'int32'
|
|
138
|
+
});
|
|
139
|
+
console.log( x );
|
|
140
|
+
|
|
141
|
+
var y = discreteUniform( 10, -5, 5, {
|
|
142
|
+
'dtype': 'int32'
|
|
143
|
+
});
|
|
144
|
+
console.log( y );
|
|
145
|
+
|
|
146
|
+
var out = countIfs( x, naryFunction( isPositiveInteger, 1 ), y, naryFunction( isNegativeInteger, 1 ) );
|
|
147
|
+
console.log( out );
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
</section>
|
|
151
|
+
|
|
152
|
+
<!-- /.examples -->
|
|
153
|
+
|
|
154
|
+
<!-- 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. -->
|
|
155
|
+
|
|
156
|
+
<section class="references">
|
|
157
|
+
|
|
158
|
+
</section>
|
|
159
|
+
|
|
160
|
+
<!-- /.references -->
|
|
161
|
+
|
|
162
|
+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
|
|
163
|
+
|
|
164
|
+
<section class="related">
|
|
165
|
+
|
|
166
|
+
</section>
|
|
167
|
+
|
|
168
|
+
<!-- /.related -->
|
|
169
|
+
|
|
170
|
+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
<section class="main-repo" >
|
|
174
|
+
|
|
175
|
+
* * *
|
|
176
|
+
|
|
177
|
+
## Notice
|
|
178
|
+
|
|
179
|
+
This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
|
|
180
|
+
|
|
181
|
+
For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib].
|
|
182
|
+
|
|
183
|
+
#### Community
|
|
184
|
+
|
|
185
|
+
[![Chat][chat-image]][chat-url]
|
|
186
|
+
|
|
187
|
+
---
|
|
188
|
+
|
|
189
|
+
## License
|
|
190
|
+
|
|
191
|
+
See [LICENSE][stdlib-license].
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
## Copyright
|
|
195
|
+
|
|
196
|
+
Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
|
|
197
|
+
|
|
198
|
+
</section>
|
|
199
|
+
|
|
200
|
+
<!-- /.stdlib -->
|
|
201
|
+
|
|
202
|
+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
203
|
+
|
|
204
|
+
<section class="links">
|
|
205
|
+
|
|
206
|
+
[npm-image]: http://img.shields.io/npm/v/@stdlib/array-base-count-ifs.svg
|
|
207
|
+
[npm-url]: https://npmjs.org/package/@stdlib/array-base-count-ifs
|
|
208
|
+
|
|
209
|
+
[test-image]: https://github.com/stdlib-js/array-base-count-ifs/actions/workflows/test.yml/badge.svg?branch=v0.1.0
|
|
210
|
+
[test-url]: https://github.com/stdlib-js/array-base-count-ifs/actions/workflows/test.yml?query=branch:v0.1.0
|
|
211
|
+
|
|
212
|
+
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/array-base-count-ifs/main.svg
|
|
213
|
+
[coverage-url]: https://codecov.io/github/stdlib-js/array-base-count-ifs?branch=main
|
|
214
|
+
|
|
215
|
+
<!--
|
|
216
|
+
|
|
217
|
+
[dependencies-image]: https://img.shields.io/david/stdlib-js/array-base-count-ifs.svg
|
|
218
|
+
[dependencies-url]: https://david-dm.org/stdlib-js/array-base-count-ifs/main
|
|
219
|
+
|
|
220
|
+
-->
|
|
221
|
+
|
|
222
|
+
[chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
|
|
223
|
+
[chat-url]: https://stdlib.zulipchat.com
|
|
224
|
+
|
|
225
|
+
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
226
|
+
|
|
227
|
+
[stdlib-authors]: https://github.com/stdlib-js/stdlib/graphs/contributors
|
|
228
|
+
|
|
229
|
+
[umd]: https://github.com/umdjs/umd
|
|
230
|
+
[es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
|
|
231
|
+
|
|
232
|
+
[deno-url]: https://github.com/stdlib-js/array-base-count-ifs/tree/deno
|
|
233
|
+
[deno-readme]: https://github.com/stdlib-js/array-base-count-ifs/blob/deno/README.md
|
|
234
|
+
[umd-url]: https://github.com/stdlib-js/array-base-count-ifs/tree/umd
|
|
235
|
+
[umd-readme]: https://github.com/stdlib-js/array-base-count-ifs/blob/umd/README.md
|
|
236
|
+
[esm-url]: https://github.com/stdlib-js/array-base-count-ifs/tree/esm
|
|
237
|
+
[esm-readme]: https://github.com/stdlib-js/array-base-count-ifs/blob/esm/README.md
|
|
238
|
+
[branches-url]: https://github.com/stdlib-js/array-base-count-ifs/blob/main/branches.md
|
|
239
|
+
|
|
240
|
+
[stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-base-count-ifs/main/LICENSE
|
|
241
|
+
|
|
242
|
+
[@stdlib/array/complex128]: https://www.npmjs.com/package/@stdlib/array-complex128
|
|
243
|
+
|
|
244
|
+
[@stdlib/array/complex64]: https://www.npmjs.com/package/@stdlib/array-complex64
|
|
245
|
+
|
|
246
|
+
</section>
|
|
247
|
+
|
|
248
|
+
<!-- /.links -->
|
package/SECURITY.md
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";var g=function(t,r){return function(){return r||t((r={exports:{}}).exports,r),r.exports}};var c=g(function(k,v){
|
|
2
|
+
var f=require('@stdlib/array-base-arraylike2object/dist'),l=require('@stdlib/array-base-zero-to/dist');function i(t,r,s){var a,n,e,o,u;for(a=t.data,n=t.accessors[0],u=0,e=0;e<r.length;e++)o=r[e],s(n(a,o),o,a)&&(r[u]=o,u+=1);return r.length=u,r}function h(t,r,s){var a,n,e;for(e=0,a=0;a<r.length;a++)n=r[a],s(t[n],n,t)&&(r[e]=n,e+=1);return r.length=e,r}function m(){var t,r,s,a,n,e;for(r=[],t=[],e=0;e<arguments.length;e+=2)r.push(f(arguments[e])),t.push(arguments[e+1]);for(s=arguments[0].length,a=l(s),e=0;e<r.length;e++)n=r[e],n.accessorProtocol?a=i(n,a,t[e]):a=h(n.data,a,t[e]);return a.length}v.exports=m
|
|
3
|
+
});var p=c();module.exports=p;
|
|
4
|
+
/** @license Apache-2.0 */
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../lib/main.js", "../lib/index.js"],
|
|
4
|
+
"sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar zeroTo = require( '@stdlib/array-base-zero-to' );\n\n\n// FUNCTIONS //\n\n/**\n* Returns an array of indices corresponding to the elements of an input array which pass a test implemented by a predicate function.\n*\n* @private\n* @param {Collection} x - input array\n* @param {Array<number>} idx - list of indices\n* @param {Function} predicate - predicate function\n* @returns {Array<number>} updated list of indices\n*\n* @example\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );\n* var zeroTo = require( '@stdlib/array-base-zero-to' );\n*\n* function predicate( v ) {\n* return ( v > 0 );\n* }\n*\n* var x = arraylike2object( toAccessorArray( [ -1, 2, 3, -4, 5 ] ) );\n* var idx = zeroTo( 5 );\n*\n* var out = accessors( x, idx, predicate );\n* // returns [ 1, 2, 4 ]\n*/\nfunction accessors( x, idx, predicate ) {\n\tvar buf;\n\tvar get;\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tbuf = x.data;\n\tget = x.accessors[ 0 ];\n\n\tk = 0;\n\tfor ( i = 0; i < idx.length; i++ ) {\n\t\tj = idx[ i ];\n\t\tif ( predicate( get( buf, j ), j, buf ) ) {\n\t\t\tidx[ k ] = j;\n\t\t\tk += 1;\n\t\t}\n\t}\n\tidx.length = k;\n\treturn idx;\n}\n\n/**\n* Returns an array of indices corresponding to the elements of an input array which pass a test implemented by a predicate function.\n*\n* @private\n* @param {Collection} x - input array\n* @param {Array<number>} idx - list of indices\n* @param {Function} predicate - predicate function\n* @returns {Array<number>} updated list of indices\n*\n* @example\n* var zeroTo = require( '@stdlib/array-base-zero-to' );\n*\n* function predicate( v ) {\n* return ( v > 0 );\n* }\n*\n* var x = [ -1, 2, 3, -4, 5 ];\n* var idx = zeroTo( 5 );\n*\n* var out = indexed( x, idx, predicate );\n* // returns [ 1, 2, 4 ]\n*/\nfunction indexed( x, idx, predicate ) {\n\tvar i;\n\tvar j;\n\tvar k;\n\n\tk = 0;\n\tfor ( i = 0; i < idx.length; i++ ) {\n\t\tj = idx[ i ];\n\t\tif ( predicate( x[ j ], j, x ) ) {\n\t\t\tidx[ k ] = j;\n\t\t\tk += 1;\n\t\t}\n\t}\n\tidx.length = k;\n\treturn idx;\n}\n\n\n// MAIN //\n\n/**\n* Performs element-wise evaluation of one or more input arrays according to provided predicate functions and counts the number of elements for which all predicates respectively return `true`.\n*\n* @param {Collection} x0 - first input array\n* @param {Function} predicate0 - first predicate function\n* @param {Collection} [x1] - second input array\n* @param {Function} [predicate1] - second predicate function\n* @param {Collection} [x2] - third input array\n* @param {Function} [predicate2] - third predicate function\n* @param {...(Collection|Function)} [args] - additional input arrays and predicate functions\n* @returns {NonNegativeInteger} result\n*\n* @example\n* function predicate0( value ) {\n* return ( value > 0 );\n* }\n*\n* function predicate1( value ) {\n* return ( value < 3 );\n* }\n*\n* var x0 = [ 0, 1, 0, 1, 2 ];\n* var x1 = [ 2, 3, 1, 2, 5 ];\n*\n* var n = countIfs( x0, predicate0, x1, predicate1 );\n* // returns 1\n*/\nfunction countIfs() {\n\tvar predicates;\n\tvar arrays;\n\tvar len;\n\tvar idx;\n\tvar x;\n\tvar i;\n\n\tarrays = [];\n\tpredicates = [];\n\tfor ( i = 0; i < arguments.length; i += 2 ) {\n\t\tarrays.push( arraylike2object( arguments[ i ] ) );\n\t\tpredicates.push( arguments[ i+1 ] );\n\t}\n\n\tlen = arguments[ 0 ].length;\n\tidx = zeroTo( len );\n\tfor ( i = 0; i < arrays.length; i++ ) {\n\t\tx = arrays[ i ];\n\t\tif ( x.accessorProtocol ) {\n\t\t\tidx = accessors( x, idx, predicates[ i ] );\n\t\t} else {\n\t\t\tidx = indexed( x.data, idx, predicates[ i ] );\n\t\t}\n\t}\n\treturn idx.length;\n}\n\n\n// EXPORTS //\n\nmodule.exports = countIfs;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2025 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Perform element-wise evaluation of one or more input arrays according to provided predicate functions and count the number of elements for which all predicates respectively return `true`.\n*\n* @module @stdlib/array-base-count-ifs\n*\n* @example\n* var countIfs = require( '@stdlib/array-base-count-ifs' );\n*\n* function predicate0( value ) {\n* return ( value > 0 );\n* }\n*\n* function predicate1( value ) {\n* return ( value < 3 );\n* }\n*\n* var x0 = [ 0, 1, 0, 1, 2 ];\n* var x1 = [ 2, 3, 1, 2, 5 ];\n*\n* var n = countIfs( x0, predicate0, x1, predicate1 );\n* // returns 1\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
|
|
5
|
+
"mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAmB,QAAS,qCAAsC,EAClEC,EAAS,QAAS,4BAA6B,EA6BnD,SAASC,EAAWC,EAAGC,EAAKC,EAAY,CACvC,IAAIC,EACAC,EACAC,EACAC,EACAC,EAMJ,IAJAJ,EAAMH,EAAE,KACRI,EAAMJ,EAAE,UAAW,CAAE,EAErBO,EAAI,EACEF,EAAI,EAAGA,EAAIJ,EAAI,OAAQI,IAC5BC,EAAIL,EAAKI,CAAE,EACNH,EAAWE,EAAKD,EAAKG,CAAE,EAAGA,EAAGH,CAAI,IACrCF,EAAKM,CAAE,EAAID,EACXC,GAAK,GAGP,OAAAN,EAAI,OAASM,EACNN,CACR,CAwBA,SAASO,EAASR,EAAGC,EAAKC,EAAY,CACrC,IAAIG,EACAC,EACAC,EAGJ,IADAA,EAAI,EACEF,EAAI,EAAGA,EAAIJ,EAAI,OAAQI,IAC5BC,EAAIL,EAAKI,CAAE,EACNH,EAAWF,EAAGM,CAAE,EAAGA,EAAGN,CAAE,IAC5BC,EAAKM,CAAE,EAAID,EACXC,GAAK,GAGP,OAAAN,EAAI,OAASM,EACNN,CACR,CAgCA,SAASQ,GAAW,CACnB,IAAIC,EACAC,EACAC,EACAX,EACAD,EACAK,EAIJ,IAFAM,EAAS,CAAC,EACVD,EAAa,CAAC,EACRL,EAAI,EAAGA,EAAI,UAAU,OAAQA,GAAK,EACvCM,EAAO,KAAMd,EAAkB,UAAWQ,CAAE,CAAE,CAAE,EAChDK,EAAW,KAAM,UAAWL,EAAE,CAAE,CAAE,EAKnC,IAFAO,EAAM,UAAW,CAAE,EAAE,OACrBX,EAAMH,EAAQc,CAAI,EACZP,EAAI,EAAGA,EAAIM,EAAO,OAAQN,IAC/BL,EAAIW,EAAQN,CAAE,EACTL,EAAE,iBACNC,EAAMF,EAAWC,EAAGC,EAAKS,EAAYL,CAAE,CAAE,EAEzCJ,EAAMO,EAASR,EAAE,KAAMC,EAAKS,EAAYL,CAAE,CAAE,EAG9C,OAAOJ,EAAI,MACZ,CAKAL,EAAO,QAAUa,ICjIjB,IAAII,EAAO,IAKX,OAAO,QAAUA",
|
|
6
|
+
"names": ["require_main", "__commonJSMin", "exports", "module", "arraylike2object", "zeroTo", "accessors", "x", "idx", "predicate", "buf", "get", "i", "j", "k", "indexed", "countIfs", "predicates", "arrays", "len", "main"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2025 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
|
+
// TypeScript Version: 4.1
|
|
20
|
+
|
|
21
|
+
/// <reference types="@stdlib/types"/>
|
|
22
|
+
|
|
23
|
+
import { Collection, AccessorArrayLike } from '@stdlib/types/array';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Input array.
|
|
27
|
+
*/
|
|
28
|
+
type InputArray<T> = Collection<T> | AccessorArrayLike<T>;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Returns a boolean indicating whether an element passes a test.
|
|
32
|
+
*
|
|
33
|
+
* @returns boolean indicating whether an element passes a test
|
|
34
|
+
*/
|
|
35
|
+
type Nullary = () => boolean;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Returns a boolean indicating whether an element passes a test.
|
|
39
|
+
*
|
|
40
|
+
* @param value - current array element
|
|
41
|
+
* @returns boolean indicating whether an element passes a test
|
|
42
|
+
*/
|
|
43
|
+
type Unary<T> = ( value: T ) => boolean;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Returns a boolean indicating whether an element passes a test.
|
|
47
|
+
*
|
|
48
|
+
* @param value - current array element
|
|
49
|
+
* @param index - current array element index
|
|
50
|
+
* @returns boolean indicating whether an element passes a test
|
|
51
|
+
*/
|
|
52
|
+
type Binary<T> = ( value: T, index: number ) => boolean;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Returns a boolean indicating whether an element passes a test.
|
|
56
|
+
*
|
|
57
|
+
* @param value - current array element
|
|
58
|
+
* @param index - current array element index
|
|
59
|
+
* @param arr - input array
|
|
60
|
+
* @returns boolean indicating whether an element passes a test
|
|
61
|
+
*/
|
|
62
|
+
type Ternary<T, U> = ( value: T, index: number, arr: U ) => boolean;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Returns a boolean indicating whether an element passes a test.
|
|
66
|
+
*
|
|
67
|
+
* @param value - current array element
|
|
68
|
+
* @param index - current array element index
|
|
69
|
+
* @param arr - input array
|
|
70
|
+
* @returns boolean indicating whether an element passes a test
|
|
71
|
+
*/
|
|
72
|
+
type Predicate<T, U> = Nullary | Unary<U> | Binary<U> | Ternary<T, U>;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Performs element-wise evaluation of one or more input arrays according to provided predicate functions and counts the number of elements for which all predicates respectively return `true`.
|
|
76
|
+
*
|
|
77
|
+
* @param x0 - input array
|
|
78
|
+
* @param predicate0 - predicate function
|
|
79
|
+
* @returns result
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* function predicate0( v ) {
|
|
83
|
+
* return v > 0;
|
|
84
|
+
* }
|
|
85
|
+
*
|
|
86
|
+
* var x0 = [ 0, 1, 0, 1, 1 ];
|
|
87
|
+
*
|
|
88
|
+
* var n = countIfs( x0, predicate0 );
|
|
89
|
+
* // returns 3
|
|
90
|
+
*/
|
|
91
|
+
declare function countIfs<T = unknown, U extends InputArray<T> = InputArray<T>>( x0: U, predicate0: Predicate<T, U> ): number;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Performs element-wise evaluation of one or more input arrays according to provided predicate functions and counts the number of elements for which all predicates respectively return `true`.
|
|
95
|
+
*
|
|
96
|
+
* @param x0 - first input array
|
|
97
|
+
* @param predicate0 - first predicate function
|
|
98
|
+
* @param x1 - second input array
|
|
99
|
+
* @param predicate1 - second predicate function
|
|
100
|
+
* @returns result
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* function predicate0( v ) {
|
|
104
|
+
* return v > 0;
|
|
105
|
+
* }
|
|
106
|
+
*
|
|
107
|
+
* function predicate1( v ) {
|
|
108
|
+
* return v < 0;
|
|
109
|
+
* }
|
|
110
|
+
*
|
|
111
|
+
* var x0 = [ 0, 1, 0, 1, 1 ];
|
|
112
|
+
* var x1 = [ -1, 2, 4, -5, -8 ];
|
|
113
|
+
*
|
|
114
|
+
* var n = countIfs( x0, predicate0, x1, predicate1 );
|
|
115
|
+
* // returns 2
|
|
116
|
+
*/
|
|
117
|
+
declare function countIfs<T = unknown, U extends InputArray<T> = InputArray<T>>( x0: U, predicate0: Predicate<T, U>, x1: U, predicate1: Predicate<T, U> ): number;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Performs element-wise evaluation of one or more input arrays according to provided predicate functions and counts the number of elements for which all predicates respectively return `true`.
|
|
121
|
+
*
|
|
122
|
+
* @param x0 - first input array
|
|
123
|
+
* @param predicate0 - first predicate function
|
|
124
|
+
* @param x1 - second input array
|
|
125
|
+
* @param predicate1 - second predicate function
|
|
126
|
+
* @param x2 - third input array
|
|
127
|
+
* @param predicate2 - third predicate function
|
|
128
|
+
* @returns result
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* function predicate0( v ) {
|
|
132
|
+
* return v > 0;
|
|
133
|
+
* }
|
|
134
|
+
*
|
|
135
|
+
* function predicate1( v ) {
|
|
136
|
+
* return v < 0;
|
|
137
|
+
* }
|
|
138
|
+
*
|
|
139
|
+
* function predicate2( v ) {
|
|
140
|
+
* return v % 2 === 0;
|
|
141
|
+
* }
|
|
142
|
+
*
|
|
143
|
+
* var x0 = [ 0, 1, 0, 1, 1 ];
|
|
144
|
+
* var x1 = [ -1, -2, 4, 5, -8 ];
|
|
145
|
+
* var x2 = [ 0, 4, 3, 2, 12 ];
|
|
146
|
+
*
|
|
147
|
+
* var n = countIfs( x0, predicate0, x1, predicate1, x2, predicate2 );
|
|
148
|
+
* // returns 2
|
|
149
|
+
*/
|
|
150
|
+
declare function countIfs<T = unknown, U extends InputArray<T> = InputArray<T>>( x0: U, predicate0: Predicate<T, U>, x1: U, predicate1: Predicate<T, U>, x2: U, predicate2: Predicate<T, U> ): number;
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Performs element-wise evaluation of one or more input arrays according to provided predicate functions and counts the number of elements for which all predicates respectively return `true`.
|
|
154
|
+
*
|
|
155
|
+
* @param x0 - first input array
|
|
156
|
+
* @param predicate0 - first predicate function
|
|
157
|
+
* @param x1 - second input array
|
|
158
|
+
* @param predicate1 - second predicate function
|
|
159
|
+
* @param x2 - third input array
|
|
160
|
+
* @param predicate2 - third predicate function
|
|
161
|
+
* @param x3 - fourth input array
|
|
162
|
+
* @param predicate3 - fourth predicate function
|
|
163
|
+
* @returns result
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* function predicate0( v ) {
|
|
167
|
+
* return v > 0;
|
|
168
|
+
* }
|
|
169
|
+
*
|
|
170
|
+
* function predicate1( v ) {
|
|
171
|
+
* return v < 0;
|
|
172
|
+
* }
|
|
173
|
+
*
|
|
174
|
+
* function predicate2( v ) {
|
|
175
|
+
* return v % 2 === 0;
|
|
176
|
+
* }
|
|
177
|
+
*
|
|
178
|
+
* function predicate3( v ) {
|
|
179
|
+
* return v % 2 !== 0;
|
|
180
|
+
* }
|
|
181
|
+
*
|
|
182
|
+
* var x0 = [ 0, 1, 0, 1, 1 ];
|
|
183
|
+
* var x1 = [ -1, -2, 4, 5, -8 ];
|
|
184
|
+
* var x2 = [ 0, 4, 3, 2, 12 ];
|
|
185
|
+
* var x3 = [ 2, 9, 3, 6, 5 ];
|
|
186
|
+
*
|
|
187
|
+
* var n = countIfs( x0, predicate0, x1, predicate1, x3, predicate3 );
|
|
188
|
+
* // returns 2
|
|
189
|
+
*/
|
|
190
|
+
declare function countIfs<T = unknown, U extends InputArray<T> = InputArray<T>>( x0: U, predicate0: Predicate<T, U>, x1: U, predicate1: Predicate<T, U>, x2: U, predicate2: Predicate<T, U>, x3: U, predicate3: Predicate<T, U> ): number;
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Performs element-wise evaluation of one or more input arrays according to provided predicate functions and counts the number of elements for which all predicates respectively return `true`.
|
|
194
|
+
*
|
|
195
|
+
* @param x0 - first input array
|
|
196
|
+
* @param predicate0 - first predicate function
|
|
197
|
+
* @param x1 - second input array
|
|
198
|
+
* @param predicate1 - second predicate function
|
|
199
|
+
* @param x2 - third input array
|
|
200
|
+
* @param predicate2 - third predicate function
|
|
201
|
+
* @param x3 - fourth input array
|
|
202
|
+
* @param predicate3 - fourth predicate function
|
|
203
|
+
* @param x4 - fifth input array
|
|
204
|
+
* @param predicate4 - fifth predicate function
|
|
205
|
+
* @param args - additional input arrays and predicate functions
|
|
206
|
+
* @returns result
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* function predicate0( v ) {
|
|
210
|
+
* return v > 0;
|
|
211
|
+
* }
|
|
212
|
+
*
|
|
213
|
+
* function predicate1( v ) {
|
|
214
|
+
* return v < 0;
|
|
215
|
+
* }
|
|
216
|
+
*
|
|
217
|
+
* function predicate2( v ) {
|
|
218
|
+
* return v % 2 === 0;
|
|
219
|
+
* }
|
|
220
|
+
*
|
|
221
|
+
* function predicate3( v ) {
|
|
222
|
+
* return v % 2 !== 0;
|
|
223
|
+
* }
|
|
224
|
+
*
|
|
225
|
+
* function predicate4( v ) {
|
|
226
|
+
* return v === true;
|
|
227
|
+
* }
|
|
228
|
+
*
|
|
229
|
+
* var x0 = [ 0, 1, 0, 1, 1 ];
|
|
230
|
+
* var x1 = [ -1, -2, 4, 5, -8 ];
|
|
231
|
+
* var x2 = [ 0, 4, 3, 2, 12 ];
|
|
232
|
+
* var x3 = [ 2, 9, 3, 6, 5 ];
|
|
233
|
+
* var x4 = [ false, true, false, true, true ];
|
|
234
|
+
*
|
|
235
|
+
* var n = countIfs( x0, predicate0, x1, predicate1, x3, predicate3, x4, predicate4 );
|
|
236
|
+
* // returns 2
|
|
237
|
+
*/
|
|
238
|
+
declare function countIfs<T = unknown, U extends InputArray<T> = InputArray<T>>( x0: U, predicate0: Predicate<T, U>, x1: U, predicate1: Predicate<T, U>, x2: U, predicate2: Predicate<T, U>, x3: U, predicate3: Predicate<T, U>, x4: U, predicate4: Predicate<T, U>, ...args: Array<U | Predicate<T, U>> ): number;
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
// EXPORTS //
|
|
242
|
+
|
|
243
|
+
export = countIfs;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2025 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
|
+
/**
|
|
22
|
+
* Perform element-wise evaluation of one or more input arrays according to provided predicate functions and count the number of elements for which all predicates respectively return `true`.
|
|
23
|
+
*
|
|
24
|
+
* @module @stdlib/array-base-count-ifs
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* var countIfs = require( '@stdlib/array-base-count-ifs' );
|
|
28
|
+
*
|
|
29
|
+
* function predicate0( value ) {
|
|
30
|
+
* return ( value > 0 );
|
|
31
|
+
* }
|
|
32
|
+
*
|
|
33
|
+
* function predicate1( value ) {
|
|
34
|
+
* return ( value < 3 );
|
|
35
|
+
* }
|
|
36
|
+
*
|
|
37
|
+
* var x0 = [ 0, 1, 0, 1, 2 ];
|
|
38
|
+
* var x1 = [ 2, 3, 1, 2, 5 ];
|
|
39
|
+
*
|
|
40
|
+
* var n = countIfs( x0, predicate0, x1, predicate1 );
|
|
41
|
+
* // returns 1
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
// MODULES //
|
|
45
|
+
|
|
46
|
+
var main = require( './main.js' );
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
// EXPORTS //
|
|
50
|
+
|
|
51
|
+
module.exports = main;
|
package/lib/main.js
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2025 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 arraylike2object = require( '@stdlib/array-base-arraylike2object' );
|
|
24
|
+
var zeroTo = require( '@stdlib/array-base-zero-to' );
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
// FUNCTIONS //
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Returns an array of indices corresponding to the elements of an input array which pass a test implemented by a predicate function.
|
|
31
|
+
*
|
|
32
|
+
* @private
|
|
33
|
+
* @param {Collection} x - input array
|
|
34
|
+
* @param {Array<number>} idx - list of indices
|
|
35
|
+
* @param {Function} predicate - predicate function
|
|
36
|
+
* @returns {Array<number>} updated list of indices
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );
|
|
40
|
+
* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );
|
|
41
|
+
* var zeroTo = require( '@stdlib/array-base-zero-to' );
|
|
42
|
+
*
|
|
43
|
+
* function predicate( v ) {
|
|
44
|
+
* return ( v > 0 );
|
|
45
|
+
* }
|
|
46
|
+
*
|
|
47
|
+
* var x = arraylike2object( toAccessorArray( [ -1, 2, 3, -4, 5 ] ) );
|
|
48
|
+
* var idx = zeroTo( 5 );
|
|
49
|
+
*
|
|
50
|
+
* var out = accessors( x, idx, predicate );
|
|
51
|
+
* // returns [ 1, 2, 4 ]
|
|
52
|
+
*/
|
|
53
|
+
function accessors( x, idx, predicate ) {
|
|
54
|
+
var buf;
|
|
55
|
+
var get;
|
|
56
|
+
var i;
|
|
57
|
+
var j;
|
|
58
|
+
var k;
|
|
59
|
+
|
|
60
|
+
buf = x.data;
|
|
61
|
+
get = x.accessors[ 0 ];
|
|
62
|
+
|
|
63
|
+
k = 0;
|
|
64
|
+
for ( i = 0; i < idx.length; i++ ) {
|
|
65
|
+
j = idx[ i ];
|
|
66
|
+
if ( predicate( get( buf, j ), j, buf ) ) {
|
|
67
|
+
idx[ k ] = j;
|
|
68
|
+
k += 1;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
idx.length = k;
|
|
72
|
+
return idx;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Returns an array of indices corresponding to the elements of an input array which pass a test implemented by a predicate function.
|
|
77
|
+
*
|
|
78
|
+
* @private
|
|
79
|
+
* @param {Collection} x - input array
|
|
80
|
+
* @param {Array<number>} idx - list of indices
|
|
81
|
+
* @param {Function} predicate - predicate function
|
|
82
|
+
* @returns {Array<number>} updated list of indices
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* var zeroTo = require( '@stdlib/array-base-zero-to' );
|
|
86
|
+
*
|
|
87
|
+
* function predicate( v ) {
|
|
88
|
+
* return ( v > 0 );
|
|
89
|
+
* }
|
|
90
|
+
*
|
|
91
|
+
* var x = [ -1, 2, 3, -4, 5 ];
|
|
92
|
+
* var idx = zeroTo( 5 );
|
|
93
|
+
*
|
|
94
|
+
* var out = indexed( x, idx, predicate );
|
|
95
|
+
* // returns [ 1, 2, 4 ]
|
|
96
|
+
*/
|
|
97
|
+
function indexed( x, idx, predicate ) {
|
|
98
|
+
var i;
|
|
99
|
+
var j;
|
|
100
|
+
var k;
|
|
101
|
+
|
|
102
|
+
k = 0;
|
|
103
|
+
for ( i = 0; i < idx.length; i++ ) {
|
|
104
|
+
j = idx[ i ];
|
|
105
|
+
if ( predicate( x[ j ], j, x ) ) {
|
|
106
|
+
idx[ k ] = j;
|
|
107
|
+
k += 1;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
idx.length = k;
|
|
111
|
+
return idx;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
// MAIN //
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Performs element-wise evaluation of one or more input arrays according to provided predicate functions and counts the number of elements for which all predicates respectively return `true`.
|
|
119
|
+
*
|
|
120
|
+
* @param {Collection} x0 - first input array
|
|
121
|
+
* @param {Function} predicate0 - first predicate function
|
|
122
|
+
* @param {Collection} [x1] - second input array
|
|
123
|
+
* @param {Function} [predicate1] - second predicate function
|
|
124
|
+
* @param {Collection} [x2] - third input array
|
|
125
|
+
* @param {Function} [predicate2] - third predicate function
|
|
126
|
+
* @param {...(Collection|Function)} [args] - additional input arrays and predicate functions
|
|
127
|
+
* @returns {NonNegativeInteger} result
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* function predicate0( value ) {
|
|
131
|
+
* return ( value > 0 );
|
|
132
|
+
* }
|
|
133
|
+
*
|
|
134
|
+
* function predicate1( value ) {
|
|
135
|
+
* return ( value < 3 );
|
|
136
|
+
* }
|
|
137
|
+
*
|
|
138
|
+
* var x0 = [ 0, 1, 0, 1, 2 ];
|
|
139
|
+
* var x1 = [ 2, 3, 1, 2, 5 ];
|
|
140
|
+
*
|
|
141
|
+
* var n = countIfs( x0, predicate0, x1, predicate1 );
|
|
142
|
+
* // returns 1
|
|
143
|
+
*/
|
|
144
|
+
function countIfs() {
|
|
145
|
+
var predicates;
|
|
146
|
+
var arrays;
|
|
147
|
+
var len;
|
|
148
|
+
var idx;
|
|
149
|
+
var x;
|
|
150
|
+
var i;
|
|
151
|
+
|
|
152
|
+
arrays = [];
|
|
153
|
+
predicates = [];
|
|
154
|
+
for ( i = 0; i < arguments.length; i += 2 ) {
|
|
155
|
+
arrays.push( arraylike2object( arguments[ i ] ) );
|
|
156
|
+
predicates.push( arguments[ i+1 ] );
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
len = arguments[ 0 ].length;
|
|
160
|
+
idx = zeroTo( len );
|
|
161
|
+
for ( i = 0; i < arrays.length; i++ ) {
|
|
162
|
+
x = arrays[ i ];
|
|
163
|
+
if ( x.accessorProtocol ) {
|
|
164
|
+
idx = accessors( x, idx, predicates[ i ] );
|
|
165
|
+
} else {
|
|
166
|
+
idx = indexed( x.data, idx, predicates[ i ] );
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return idx.length;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
// EXPORTS //
|
|
174
|
+
|
|
175
|
+
module.exports = countIfs;
|
package/package.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stdlib/array-base-count-ifs",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Perform element-wise evaluation of one or more input arrays according to provided predicate functions and count the number of elements for which all predicates respectively return `true`.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "The Stdlib Authors",
|
|
8
|
+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
|
|
9
|
+
},
|
|
10
|
+
"contributors": [
|
|
11
|
+
{
|
|
12
|
+
"name": "The Stdlib Authors",
|
|
13
|
+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
|
|
14
|
+
}
|
|
15
|
+
],
|
|
16
|
+
"main": "./lib",
|
|
17
|
+
"directories": {
|
|
18
|
+
"doc": "./docs",
|
|
19
|
+
"lib": "./lib",
|
|
20
|
+
"dist": "./dist"
|
|
21
|
+
},
|
|
22
|
+
"types": "./docs/types",
|
|
23
|
+
"scripts": {},
|
|
24
|
+
"homepage": "https://stdlib.io",
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git://github.com/stdlib-js/array-base-count-ifs.git"
|
|
28
|
+
},
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@stdlib/array-base-arraylike2object": "^0.2.1",
|
|
34
|
+
"@stdlib/array-base-zero-to": "^0.2.1"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {},
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">=0.10.0",
|
|
39
|
+
"npm": ">2.7.0"
|
|
40
|
+
},
|
|
41
|
+
"os": [
|
|
42
|
+
"aix",
|
|
43
|
+
"darwin",
|
|
44
|
+
"freebsd",
|
|
45
|
+
"linux",
|
|
46
|
+
"macos",
|
|
47
|
+
"openbsd",
|
|
48
|
+
"sunos",
|
|
49
|
+
"win32",
|
|
50
|
+
"windows"
|
|
51
|
+
],
|
|
52
|
+
"keywords": [
|
|
53
|
+
"stdlib",
|
|
54
|
+
"array",
|
|
55
|
+
"count",
|
|
56
|
+
"sum",
|
|
57
|
+
"summation",
|
|
58
|
+
"countif",
|
|
59
|
+
"countifs",
|
|
60
|
+
"range",
|
|
61
|
+
"total",
|
|
62
|
+
"truthy"
|
|
63
|
+
],
|
|
64
|
+
"funding": {
|
|
65
|
+
"type": "opencollective",
|
|
66
|
+
"url": "https://opencollective.com/stdlib"
|
|
67
|
+
}
|
|
68
|
+
}
|