Skip to content

Instantly share code, notes, and snippets.

View shanelonergan's full-sized avatar
⌨️

Shane Lonergan shanelonergan

⌨️
View GitHub Profile
unique_dates.reduce(today) do | memo, date |
yesterday = memo.yesterday.to_date
end
array_variable.reduce(starting_value) do | accumulator, current_element |
action
end
[1, 2, 3].reduce(0) { |memo, n| memo + n }
# => 6
unique_dates.reduce(today) do | memo, date |
yesterday = memo.yesterday.to_date
if date == yesterday || date == today
streak_count += 1
memo = date
end
dates_array = self.sessions.map do |session|
session.created_at.to_date
end
unique_dates = dates_array.uniq
Time.now
=> 2019-10-15 16:16:16 -0400
Time.now.to_date
=> 2019-10-15
HTMLElement.prototype.getElementsByClassname2 = getElementsByClassName2
function getElementsByClassName2(classNameStr) {
function checkChildren(child) {
// check if the child has a matching class. If so, push the the elements array
if (child.classList.contains(classNameStr)) {
elements.push(child)
}
// check if that child has children of its own. If so, call checkChildren one each child