FaheemAhmadGul
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".
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Not a problem FaheemAhmadGul, glad I was able to help.
ASKER