Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift - Array filtering values in between two numbers

i have a small problem.

I have an array with a integer of value:

let array = [99, 42, 34, 19, 167, 30, 49, 39, 75, 175, 270, 540]

How do I get all the values between 19 and 167 for example? There has to be a better way than a for iteration through all the integer value ? this is on swift. so i am looking for answer on swift. thanks in advance

like image 540
aryan tak Avatar asked Mar 29 '26 22:03

aryan tak


1 Answers

In Swift, you can still do this using filter

let array = [99, 42, 34, 19, 167, 30, 49, 39, 75, 175, 270, 540]
let newArray = array.filter{$0 > 19 && $0 < 167}
print(newArray)
like image 171
Goma Avatar answered Apr 01 '26 10:04

Goma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!