Task: Provide an array of string exceptions, an array of string extensions as an argument to the if statement.
Let's say i have
fileExt := []string{".exe", ".bin"} fileExcept := []string{"waste.exe", "unusual.exe"} I cannot do an iteration of the form for _, fext := range fileExt {} since under this iteration there will be several more iterations, and instead of one or two iterations passed, there will be over a hundred, depending on how many arguments are specified in [] string arrays. I want to do something like lookup for values in an array, that is, if file.Ext == searchExts([]string{".exe", ".bin"}) -> if the found files have the extension .exe OR .bin , no matter in what sequence, will return the result true. I have a searchString function, but it can only search for 1 file extension, not a list of extensions, here’s the code:
func searchString(files []string, target string) string { var cFiles string sort.Strings(files) i := sort.SearchStrings(files, target) if i < len(files) && files[i] == target { cFiles = files[i] } return cFiles }