mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-06 23:06:43 +02:00
add count
This commit is contained in:
@@ -395,7 +395,7 @@ These examples incubate dotSCAD and dotSCAD refactors these examples. See [examp
|
|||||||
[**util/sorted**(lt[, cmp, key, reverse])](https://openhome.cc/eGossip/OpenSCAD/lib3x-sorted.html) | sort a list.
|
[**util/sorted**(lt[, cmp, key, reverse])](https://openhome.cc/eGossip/OpenSCAD/lib3x-sorted.html) | sort a list.
|
||||||
[**util/contains**(lt, elem)](https://openhome.cc/eGossip/OpenSCAD/lib3x-contains.html) | return `true` if `lt` contains `elem`.
|
[**util/contains**(lt, elem)](https://openhome.cc/eGossip/OpenSCAD/lib3x-contains.html) | return `true` if `lt` contains `elem`.
|
||||||
[**util/binary_search**(sorted, target[, lo, hi])](https://openhome.cc/eGossip/OpenSCAD/lib3x-binary_search.html) | search a value in a sorted list.
|
[**util/binary_search**(sorted, target[, lo, hi])](https://openhome.cc/eGossip/OpenSCAD/lib3x-binary_search.html) | search a value in a sorted list.
|
||||||
|
[**util/count**(lt, test)](https://openhome.cc/eGossip/OpenSCAD/lib3x-count.html) | return the number of times `test` return `true` in the list.
|
||||||
|
|
||||||
## Maze
|
## Maze
|
||||||
|
|
||||||
|
15
docs/lib3x-count.md
Normal file
15
docs/lib3x-count.md
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
# count
|
||||||
|
|
||||||
|
Returns the number of times `test` return `true` in the list.
|
||||||
|
|
||||||
|
**Since:** 3.3
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
- `lt` : The list.
|
||||||
|
- `test` : A testing function.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
points = [[7, 2, 2], [1, 1, 2], [3, 4, 2], [3, 4, 2], [1, 2, 3]];
|
||||||
|
assert(count(points, function(p) norm(p) > 5) == 3);
|
@@ -1 +1,11 @@
|
|||||||
|
/**
|
||||||
|
* count.scad
|
||||||
|
*
|
||||||
|
* @copyright Justin Lin, 2022
|
||||||
|
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||||
|
*
|
||||||
|
* @see https://openhome.cc/eGossip/OpenSCAD/lib3x-count.html
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
|
||||||
function count(lt, test) = len([for(elem = lt) if(test(elem)) undef]);
|
function count(lt, test) = len([for(elem = lt) if(test(elem)) undef]);
|
Reference in New Issue
Block a user