热门标签 | HotTags
当前位置:  开发笔记 > 后端 > 正文

rubylambda_pricing.rb

篇首语:本文由编程笔记#小编为大家整理,主要介绍了rubylambda_pricing.rb相关的知识,希望对你有一定的参考价值。

篇首语:本文由编程笔记#小编为大家整理,主要介绍了ruby lambda_pricing.rb相关的知识,希望对你有一定的参考价值。




food_prices_before_tax = [9, 8, 7, 6, 5, 4, 3, 2, 1]
liquor_prices_before_tax = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]
wine_prices_before_tax = [50, 40, 30, 20, 10]
food_tax = lambda { |price| price + (price * 0.07) }
liquor_tax = lambda { |price| price + (price * 0.17) }
tuesday_wine_discount = lambda { |price| price - (price * 0.15) }
food_prices_with_tax = food_prices_before_tax.map(&food_tax)
liquor_prices_with_tax = liquor_prices_before_tax.map(&liquor_tax)
wine_prices_with_tuesday_discount = wine_prices_before_tax.map(&tuesday_wine_discount)
wine_prices_with_tuesday_discount_and_tax = wine_prices_with_tuesday_discount.map(&liquor_tax)
p food_prices_with_tax
p liquor_prices_with_tax
p wine_prices_with_tuesday_discount
p wine_prices_with_tuesday_discount_and_tax
one_bottle_of_wine = 70
p liquor_tax.call(one_bottle_of_wine)
p liquor_tax.(one_bottle_of_wine)
p liquor_tax[one_bottle_of_wine]
costco_discount = ->(price) { price - (price * 0.05) }
car_prices = [70_000, 60_000, 50_000, 40_000]
car_prices.each do |car|
puts "With the Costco discount, the car costs: #{costco_discount.call(car)}"
end


推荐阅读
author-avatar
159dzhqian449_734
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有