How to resolve the algorithm Filter step by step in the Déjà Vu programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Filter step by step in the Déjà Vu 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 Déjà Vu programming language
Source code in the déjà programming language
filter pred lst:
]
for value in copy lst:
if pred @value:
@value
[
even x:
= 0 % x 2
!. filter @even [ 0 1 2 3 4 5 6 7 8 9 ]
local :lst [ 0 1 2 3 4 5 6 7 8 9 ]
filter-destructively pred lst:
local :tmp []
while lst:
pop-from lst
if pred dup:
push-to tmp
else:
drop
while tmp:
push-to lst pop-from tmp
filter-destructively @even lst
!. lst
You may also check:How to resolve the algorithm Eban numbers step by step in the EasyLang programming language
You may also check:How to resolve the algorithm Farey sequence step by step in the Fōrmulæ programming language
You may also check:How to resolve the algorithm Sierpinski triangle step by step in the TI-83 BASIC programming language
You may also check:How to resolve the algorithm Fibonacci n-step number sequences step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Walk a directory/Non-recursively step by step in the zkl programming language