Is there a method to find an element in an array that contains certain characters or strings? The following is a way of doing it, but I am curious if such a method already exists.
(
~itemStringInArrayFinder = { |array, which| var test, indices;
test = array.collect { |item, index|
if (item.asString.contains(which.asString)) { indices = indices.add(index) };
};
if (test.occurrencesOf(nil) == test.size) { nil } { indices }
}
)
~itemStringInArrayFinder.([\a, \bc, "cd" ], "c")
~itemStringInArrayFinder.([12, \1, "1d", 3 ], 1)
~itemStringInArrayFinder.([12, \1, "1d", 3 ], 3)