How to resolve the algorithm Filter step by step in the Lasso programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Filter step by step in the Lasso 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 Lasso programming language

Source code in the lasso programming language

local(original = array(1,2,3,4,5,6,7,8,9,10))
local(evens = (with item in #original where #item % 2 == 0 select #item) -> asstaticarray)
#evens


local(original = array(1,2,3,4,5,6,7,8,9,10))
with item in #original where #item % 2 != 0 do #original ->removeall(#item)
#original


  

You may also check:How to resolve the algorithm Gaussian elimination step by step in the REXX programming language
You may also check:How to resolve the algorithm Queue/Definition step by step in the ARM Assembly programming language
You may also check:How to resolve the algorithm String interpolation (included) step by step in the F# programming language
You may also check:How to resolve the algorithm Jensen's Device step by step in the AppleScript programming language
You may also check:How to resolve the algorithm Hello world/Standard error step by step in the F# programming language