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
groceryList = {} | |
groceryList['Bananas'] = true | |
groceryList['Apples'] = true | |
groceryList['Grapes'] = true | |
groceryList['Kiwis'] = true | |
groceryList['Pears'] = true | |
groceryList['Apples'] = true # dublicates will be ignored | |
console.log(Object.keys(groceryList).length == 5) | |
console.log(groceryList['Kiwis'] == true) |
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
'use strict' | |
let groceryList = new Map() | |
groceryList.set('Bananas', 6) | |
groceryList.set('Apples', 12) | |
groceryList.set('Grapes', 2) | |
groceryList.set('Kiwis', 10) | |
groceryList.set('Pears', 8) | |
console.log(groceryList.get('Kiwis') === 10) | |
console.log(groceryList.size === 5) |
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
groceryList = {} | |
groceryList['Bananas'] = 6 | |
groceryList['Apples'] = 12 | |
groceryList['Grapes'] = 2 | |
groceryList['Kiwis'] = 10 | |
groceryList['Pears'] = 8 | |
console.log(groceryList['Kiwis'] == 10) | |
console.log(Object.keys(groceryList).length == 5) |
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
subscribers.each do |subscriber_row| | |
user = User.find_by(email: subscriber_row[1]) | |
if user.nil? | |
user = User.create_by_subscribe( | |
email: subscriber_row[1], | |
first_name: subscriber_row[2], | |
last_name: subscriber_row[3] | |
) | |
end |
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
subscribers.each do |row| | |
subscriber_row = SubscriberRow.new(row) | |
user = User.find_by_or_create_by_subscribe(subscriber_row.user_hash) | |
subscriptions = Subscription.find(subscriber_row.subsc_ids) | |
if subscriber_row.subscribe? | |
user.subscribe(subscriptions) | |
user.send_greeting_email(subscriptions) | |
end | |
if subscriber_row.unsubscribe? |
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
# app/controllers/statistics_controller.rb | |
class StatisticsController < ApplicationController | |
# ... | |
def weekly | |
@weekly = [] | |
get_date.each do |date_obj| | |
day = date_obj[:start_day].strftime('%A %d-%m-%Y') | |
orders = get_orders(date_obj) | |
orders_sum = orders.map(&:price).reduce(:+) |
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
# app/statistics/weekly.html.slim | |
table.table | |
thead | |
tr | |
td Day | |
td Pizza count | |
td Orders sum | |
td Users | |
td Pizza | |
tbody |
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
# app/model/weekly_day.rb | |
WeeklyDay = Struct.new(:start_day, :end_day) do | |
def start_day_string | |
start_day.strftime('%A %d-%m-%Y') | |
end | |
end | |
# app/model/daily_statistic.rb | |
DailyStatistic = Struct.new(:day_string, :orders) do | |
def day |
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
# app/views/statistics/weekly.html.slim | |
table.table | |
thead | |
tr | |
td Day | |
td Pizza count | |
td Orders sum | |
td Users | |
td Pizza | |
tbody |
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
class Latitude | |
def initialize(value) | |
@value = value | |
end | |
def to_i | |
@value.to_i | |
end | |
end |