Link to home
Start Free TrialLog in
Avatar of FaheemAhmadGul
FaheemAhmadGulFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Swift Function that will take an array of strings and return filtered array of strings from first array of strings starting with a certain prefix

I need help with a Swift function (named myFunction) which will take two parameters. The first parameter will be an array of Strings. The second parameter will be a simple String. When myFunction is called (with its two arguments) myFunction should return me yet another array of Strings which will consist of those strings from the String Array passed to my function as an argument that start with a certain combination of letters (contained in the second argument provided to myFuntion.
To clarify my question if I have the following array of Strings:

var myFruits: [String] = ["apple", "peter", "apricot", "pear", "orange"]

and I call myFunction with the first argument being myFruits (and the second argument being "ap" ) then myFunction should return me an array of Strings named myFilteredFruits which will contain two items, "apple" and "apricot".
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of FaheemAhmadGul

ASKER

Many thanks. Greatly appreciated.
Not a problem FaheemAhmadGul, glad I was able to help.