README.md (2691B)
1 <!-- 2 3 @license Apache-2.0 4 5 Copyright (c) 2018 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 # pickBy 22 23 > Return a partial object copy containing properties for which a predicate (function) returns a truthy value. 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 pickBy = require( '@stdlib/utils/pick-by' ); 41 ``` 42 43 #### pickBy( obj, predicate ) 44 45 Returns a partial object copy containing properties for which a `predicate` returns a truthy value. 46 47 ```javascript 48 function predicate( key, value ) { 49 return ( value > 1 ); 50 } 51 52 var obj1 = { 53 'a': 1, 54 'b': 2, 55 'c': 3 56 }; 57 58 var obj2 = pickBy( obj1, predicate ); 59 // returns { 'b': 2, 'c': 3 } 60 ``` 61 62 </section> 63 64 <!-- /.usage --> 65 66 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 67 68 <section class="notes"> 69 70 ## Notes 71 72 - The function returns a **shallow** copy. 73 - The function **only** copies **own** properties. Hence, the function never copies inherited properties. 74 75 </section> 76 77 <!-- /.notes --> 78 79 <!-- Package usage examples. --> 80 81 <section class="examples"> 82 83 ## Examples 84 85 <!-- eslint no-undef: "error" --> 86 87 ```javascript 88 var pickBy = require( '@stdlib/utils/pick-by' ); 89 90 function predicate( key, value ) { 91 return ( typeof value === 'number' ); 92 } 93 94 var obj1 = { 95 'a': '1', 96 'b': 2, 97 'c': NaN, 98 'd': null 99 }; 100 101 var obj2 = pickBy( obj1, predicate ); 102 // returns { 'b': 2, 'c': NaN } 103 ``` 104 105 </section> 106 107 <!-- /.examples --> 108 109 <!-- 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. --> 110 111 <section class="references"> 112 113 </section> 114 115 <!-- /.references --> 116 117 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 118 119 <section class="links"> 120 121 </section> 122 123 <!-- /.links -->