diff --git a/README.md b/README.md index 936378bb..603dd2d8 100644 --- a/README.md +++ b/README.md @@ -137,21 +137,21 @@ These examples incubate dotSCAD and dotSCAD refactors these examples. See [examp - list - [util/bsearch](https://openhome.cc/eGossip/OpenSCAD/lib3x-bsearch.html) - [util/has](https://openhome.cc/eGossip/OpenSCAD/lib3x-has.html) - - `util/find_index` + - [util/find_index](https://openhome.cc/eGossip/OpenSCAD/lib3x-find_index.html) - [util/dedup](https://openhome.cc/eGossip/OpenSCAD/lib3x-dedup.html) - [util/flat](https://openhome.cc/eGossip/OpenSCAD/lib3x-flat.html) - [util/reverse](https://openhome.cc/eGossip/OpenSCAD/lib3x-reverse.html) - [util/slice](https://openhome.cc/eGossip/OpenSCAD/lib3x-slice.html) - [util/sort](https://openhome.cc/eGossip/OpenSCAD/lib3x-sort.html) - [util/sum](https://openhome.cc/eGossip/OpenSCAD/lib3x-sum.html) - - `util/swap` + - [util/swap](https://openhome.cc/eGossip/OpenSCAD/lib3x-swap.html) - [util/zip](https://openhome.cc/eGossip/OpenSCAD/lib3x-zip.html) - [util/every](https://openhome.cc/eGossip/OpenSCAD/lib3x-every.html) - [util/some](https://openhome.cc/eGossip/OpenSCAD/lib3x-some.html) - random - [util/choose](https://openhome.cc/eGossip/OpenSCAD/lib3x-choose.html) - [util/rand](https://openhome.cc/eGossip/OpenSCAD/lib3x-rand.html) - - `util/shuffle` + - [util/shuffle](https://openhome.cc/eGossip/OpenSCAD/lib3x-shuffle.html) - string - [util/parse_number](https://openhome.cc/eGossip/OpenSCAD/lib3x-parse_number.html) - [util/split_str](https://openhome.cc/eGossip/OpenSCAD/lib3x-split_str.html) diff --git a/docs/lib3x-find_index.md b/docs/lib3x-find_index.md new file mode 100644 index 00000000..55958997 --- /dev/null +++ b/docs/lib3x-find_index.md @@ -0,0 +1,16 @@ +# find_index + +Returns the index of the first element in the list that satisfies the testing function. If no element passed the test, it returns -1. + +**Since:** 3.0 + +## Parameters + +- `lt` : The list. +- `test` : the testing function. + +## Examples + + use ; + + assert(find_index([10, 20, 30, 40], function(e) e > 10) == 1); \ No newline at end of file diff --git a/docs/lib3x-shuffle.md b/docs/lib3x-shuffle.md new file mode 100644 index 00000000..8607428a --- /dev/null +++ b/docs/lib3x-shuffle.md @@ -0,0 +1,16 @@ +# shuffle + +Randomizes the order of the elements of a list. + +**Since:** 3.0 + +## Parameters + +- `lt` : The list to shuffle. +- `seed` : Random seed value. + +## Examples + + use ; + + echo(shuffle([1, 2, 3, 4])); \ No newline at end of file diff --git a/docs/lib3x-swap.md b/docs/lib3x-swap.md new file mode 100644 index 00000000..1618459b --- /dev/null +++ b/docs/lib3x-swap.md @@ -0,0 +1,17 @@ +# swap + +Swaps two elements in a list. + +**Since:** 3.0 + +## Parameters + +- `lt` : The list. +- `i` : The index of an element. +- `j` : The index of the other element + +## Examples + + use ; + + assert(swap([10, 20, 30, 40], 1, 3) == [10, 40, 30, 20]); \ No newline at end of file diff --git a/src/util/swap.scad b/src/util/swap.scad index a56a78f9..5e56281f 100644 --- a/src/util/swap.scad +++ b/src/util/swap.scad @@ -1,3 +1,13 @@ +/** +* swap.scad +* +* @copyright Justin Lin, 2021 +* @license https://opensource.org/licenses/lgpl-3.0.html +* +* @see https://openhome.cc/eGossip/OpenSCAD/lib3x-swap.html +* +**/ + function swap(lt, i, j) = i == j ? lt : let(