How to resolve the algorithm Filter step by step in the EchoLisp programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Filter step by step in the EchoLisp programming language
Table of Contents
Problem Statement
Select certain elements from an Array into a new Array in a generic way.
To demonstrate, select all even numbers from an Array. As an option, give a second solution which filters destructively, by modifying the original Array rather than creating a new Array.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Filter step by step in the EchoLisp programming language
Source code in the echolisp programming language
(iota 12) → { 0 1 2 3 4 5 6 7 8 9 10 11 }
;; lists
(filter even? (iota 12))
→ (0 2 4 6 8 10)
;; array (non destructive)
(vector-filter even? #(1 2 3 4 5 6 7 8 9 10 11 12 13))
→ #( 2 4 6 8 10 12)
;; sequence, infinite, lazy
(lib 'sequences)
(define evens (filter even? [0 ..]))
(take evens 12)
→ (0 2 4 6 8 10 12 14 16 18 20 22)
You may also check:How to resolve the algorithm Pi step by step in the R programming language
You may also check:How to resolve the algorithm Sort numbers lexicographically step by step in the M2000 Interpreter programming language
You may also check:How to resolve the algorithm Unicode strings step by step in the Ring programming language
You may also check:How to resolve the algorithm Calendar step by step in the Clojure programming language
You may also check:How to resolve the algorithm Flatten a list step by step in the C++ programming language