|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2023 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 | +# bifurcateEntries |
| 22 | + |
| 23 | +> Split array element entries into two groups. |
| 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 bifurcateEntries = require( '@stdlib/array/base/bifurcate-entries' ); |
| 41 | +``` |
| 42 | + |
| 43 | +#### bifurcateEntries( x, filter ) |
| 44 | + |
| 45 | +Splits array element entries into two groups. |
| 46 | + |
| 47 | +```javascript |
| 48 | +var x = [ 'beep', 'boop', 'foo', 'bar' ]; |
| 49 | +var filter = [ true, true, false, true ]; |
| 50 | + |
| 51 | +var out = bifurcateEntries( x, filter ); |
| 52 | +// returns [ [ [ 0, 'beep' ], [ 1, 'boop' ], [ 3, 'bar' ] ], [ [ 2, 'foo' ] ] ] |
| 53 | +``` |
| 54 | + |
| 55 | +</section> |
| 56 | + |
| 57 | +<!-- /.usage --> |
| 58 | + |
| 59 | +<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 60 | + |
| 61 | +<section class="notes"> |
| 62 | + |
| 63 | +## Notes |
| 64 | + |
| 65 | +- If an element in `filter` is truthy, the corresponding element in the input array `x` belongs to the first group; otherwise, the input array element belongs to the second group. |
| 66 | + |
| 67 | +</section> |
| 68 | + |
| 69 | +<!-- /.notes --> |
| 70 | + |
| 71 | +<!-- Package usage examples. --> |
| 72 | + |
| 73 | +<section class="examples"> |
| 74 | + |
| 75 | +## Examples |
| 76 | + |
| 77 | +<!-- eslint no-undef: "error" --> |
| 78 | + |
| 79 | +```javascript |
| 80 | +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); |
| 81 | +var take = require( '@stdlib/array/base/take' ); |
| 82 | +var bifurcateEntries = require( '@stdlib/array/base/bifurcate-entries' ); |
| 83 | + |
| 84 | +// Define an initial array of values: |
| 85 | +var values = [ 'beep', 'boop', 'foo', 'bar', 'woot', 'woot' ]; |
| 86 | + |
| 87 | +// Sample from the initial array to generate a random collection: |
| 88 | +var indices = discreteUniform( 100, 0, values.length-1, { |
| 89 | + 'dtype': 'generic' |
| 90 | +}); |
| 91 | +var x = take( values, indices ); |
| 92 | +// returns [...] |
| 93 | + |
| 94 | +// Randomly assign collection values to groups: |
| 95 | +var groups = discreteUniform( x.length, 0, 1, { |
| 96 | + 'dtype': 'generic' |
| 97 | +}); |
| 98 | + |
| 99 | +// Group the values: |
| 100 | +var out = bifurcateEntries( x, groups ); |
| 101 | +// returns [...] |
| 102 | + |
| 103 | +console.log( out ); |
| 104 | +``` |
| 105 | + |
| 106 | +</section> |
| 107 | + |
| 108 | +<!-- /.examples --> |
| 109 | + |
| 110 | +<!-- 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. --> |
| 111 | + |
| 112 | +<section class="references"> |
| 113 | + |
| 114 | +</section> |
| 115 | + |
| 116 | +<!-- /.references --> |
| 117 | + |
| 118 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 119 | + |
| 120 | +<section class="related"> |
| 121 | + |
| 122 | +</section> |
| 123 | + |
| 124 | +<!-- /.related --> |
| 125 | + |
| 126 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 127 | + |
| 128 | +<section class="links"> |
| 129 | + |
| 130 | +</section> |
| 131 | + |
| 132 | +<!-- /.links --> |
0 commit comments