Skip to content

Instantly share code, notes, and snippets.

@e-jigsaw
Last active August 29, 2015 14:11
Show Gist options
  • Save e-jigsaw/665f8ff0ff07a4c986a7 to your computer and use it in GitHub Desktop.
Save e-jigsaw/665f8ff0ff07a4c986a7 to your computer and use it in GitHub Desktop.
rank = (str, num)->
ary = str.split ''
target = ary[num]
ary.slice(num+1).reduce (sum, i)->
if i > target then sum + 1 else sum
, 0
ans = rank "generating", 0
console.log ans
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment