I have this array:
let numbers = [0,1,2,3,4,5,6,7,8,9]
And I want to append all numbers below 6 in this array below:
var belowSix = [Int]()
Here is what I have done and it works:
for number in numbers {
if number < 6 {
belowSix.append(number)
}
}
Question:
It feels like this can be done in a smoother way, any suggestions?
[0,1,2,3,4,2,5,6,7,8,9]in this case it will not show5in yourbelowSixarray if you useprefix(6)so better if you usefilternot theprefixbecause prefix is used to get specific objects from array startingprefix(6)with array[0,1,2,3,4,2,5,6,7,8,9], You will not get your desired result