UNPKG

mathjs

Version:

Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser with support for symbolic computation, comes with a large set of built-in functions and constants, and offers an integrated solution to work with dif

45 lines (28 loc) 1.12 kB
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. --> # Function filter Filter the items in an array or one dimensional matrix. ## Syntax ```js math.filter(x, test) ``` ### Parameters Parameter | Type | Description --------- | ---- | ----------- `x` | Matrix &#124; Array | A one dimensional matrix or array to filter `test` | Function &#124; RegExp | A function or regular expression to test items. All entries for which `test` returns true are returned. When `test` is a function, it is invoked with three parameters: the value of the element, the index of the element, and the matrix/array being traversed. The function must return a boolean. ### Returns Type | Description ---- | ----------- Matrix &#124; Array | Returns the filtered matrix. ## Examples ```js function isPositive (x) { return x > 0 } math.filter([6, -2, -1, 4, 3], isPositive) // returns [6, 4, 3] math.filter(["23", "foo", "100", "55", "bar"], /[0-9]+/) // returns ["23", "100", "55"] ``` ## See also [forEach](forEach.md), [map](map.md), [sort](sort.md)