Skip to content

Instantly share code, notes, and snippets.

@zeffii
Forked from anonymous/find.coffee
Created February 13, 2014 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeffii/8980969 to your computer and use it in GitHub Desktop.
Save zeffii/8980969 to your computer and use it in GitHub Desktop.
find index of last occurrence of token
bla = "qweronoquenr\n2424onounwerwer342342\nerw523535\n3534"
find_index_of_last = (instr, token) ->
return null if not (token in instr)
idx_shift = -1
while true
fd = instr.indexOf(token, idx_shift+1)
if fd == -1
return idx_shift
idx_shift = fd
m = find_index_of_last(bla, "\n")
console.log(m)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment