Skip to content

Instantly share code, notes, and snippets.

@js947
Last active August 29, 2015 14:02
Show Gist options
  • Save js947/560551480f6930a0dac2 to your computer and use it in GitHub Desktop.
Save js947/560551480f6930a0dac2 to your computer and use it in GitHub Desktop.
def frk a, r, b
lambda do |x|
r.call(a.call(x), b.call(x))
end
end
def sum a
a.reduce(0) do |sum, value|
sum + value
end
end
sum = method :sum
def cnt a
a.length
end
cnt = method :cnt
def div a, b
a/b
end
div = method :div
avg = frk sum, div, cnt
ans = avg.call [1.0, 2.0, 3.0, 4.0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment