John Myles White
unread,Jan 26, 2013, 9:15:02 AM1/26/13Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to julia...@googlegroups.com
Having just recently discovered anyp() and allp() in Base, I wrote a complementary function called findp(). It seems like it would be generally useful, but I'm hesitant to propose adding more things to Base. As such, I'm just leaving it below in case others have a sense for where we might want to put it:
function findp(p::Function, a::AbstractArray)
n = length(a)
indices = Array(Int, n)
t = 0
for i in 1:n
if p(a[i])
t += 1
indices[t] = i
end
end
return indices[1:t]
end
findp(iseven, [1, 2, 3, 4, 5])