How to resolve the algorithm Filter step by step in the Lisaac programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Filter step by step in the Lisaac 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 Lisaac programming language
Source code in the lisaac programming language
+ a, b : ARRAY[INTEGER];
a := ARRAY[INTEGER].create_with_capacity 10 lower 0;
b := ARRAY[INTEGER].create_with_capacity 10 lower 0;
1.to 10 do { i : INTEGER;
a.add_last i;
};
a.foreach { item : INTEGER;
(item % 2 = 0).if {
b.add_last item;
};
};
You may also check:How to resolve the algorithm Catamorphism step by step in the Elixir programming language
You may also check:How to resolve the algorithm Sorting algorithms/Counting sort step by step in the R programming language
You may also check:How to resolve the algorithm Random numbers step by step in the Java programming language
You may also check:How to resolve the algorithm Rock-paper-scissors step by step in the BBC BASIC programming language
You may also check:How to resolve the algorithm Motzkin numbers step by step in the Go programming language