# Creating a lambda
l = lambda { |name| "Hi #{name}!" }
# Executing the lambda
l.call("foo") # => Hi foo!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"window.zoomLevel": 1, | |
"editor.tabCompletion": false, | |
"editor.tabSize": 2, | |
"files.insertFinalNewline": false, | |
"editor.scrollBeyondLastLine": false, | |
"stylelint.enable": true, | |
"stylelint.config": { | |
"extends": "stylelint-config-standard", | |
"rules": { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def weight_avg_gross_profit(reports) | |
# find total weight, sum of sale_revenue | |
total_weight = reports.reduce(0) { |sum, r| sum + r.sale_revenue } | |
# find sum products | |
sum_prod = reports.reduce do |sum, r| | |
sum + (r.percent_gross_profit * r.sale_revenue) | |
end | |
# simple weight average formula, (w1*x1 + w2*x2) / (w1 + w2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def weight_avg_gross_profit(reports) | |
# find total weight, sum of sale_revenue | |
total_weight = reports.reduce(0) { |sum, r| sum + r.sale_revenue } | |
# find sum products | |
sum_prod = reports.reduce(0) do |sum, r| | |
sum + (r.percent_gross_profit * r.sale_revenue) | |
end | |
# simple weight average formula, (w1*x1 + w2*x2) / (w1 + w2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def weight_avg_gross_profit(reports) | |
weight_avg(reports, 'gross_profit') | |
end | |
def weight_avg_cogs(reports) | |
weight_avg(reports, 'cogs') | |
end | |
def weight_avg(reports, value) | |
total_weight = reports.reduce(0) { |sum, r| sum + r.sale_revenue } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
Report = Struct.new(:sale_revenue, :gross_profit, :cogs) | |
def main | |
puts '## First report ##' | |
puts 'Input revenue: ' | |
revenue1 = gets.chomp.to_f | |
puts 'Input gross profit: ' | |
gp1 = gets.chomp.to_f |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Item = Struct.new(:amount, :price, :name) do | |
def total_price | |
amount * price | |
end | |
end | |
Cart = Struct.new(:items) do | |
# total amount is finding sum of item amount | |
def total_amount | |
# a.k.a finding sum by item.amount function |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const preciseOperation = f => (a, b, decimalDigits) => { | |
decimalDigits = decimalDigits || 12 | |
+(f(a, b)).toFixed(decimalDigits) | |
} | |
const add = (a, b) => a + b | |
const minus = (a, b) => a - b | |
const multiply = (a, b) => a * b | |
const divide = (a, b) => a / b | |
export const preciseAdd = (a, b, decimalDigits) => preciseOperation(add)(a,b, decimalDigits) | |
export const preciseMinus = (a, b, decimalDigits) => preciseOperation(minus)(a,b, decimalDigits) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Your Stylesheet | |
* | |
* This stylesheet is loaded when Atom starts up and is reloaded automatically | |
* when it is changed and saved. | |
* | |
* Add your own CSS or Less to fully customize Atom. | |
* If you are unfamiliar with Less, you can read more about it here: | |
* http://lesscss.org | |
*/ |