Skip to content

Instantly share code, notes, and snippets.

View shanelonergan's full-sized avatar
⌨️

Shane Lonergan shanelonergan

⌨️
View GitHub Profile
function getElementsByClassName2(classNameStr) {
const elements = []
const firstChildren = this.children
function checkChildren(child) {
if (child.classList.contains(classNameStr)) {
elements.push(child)
}
const parent = document.getElementsByClassName('parent')
// => <div class='parent'></div>
const helloWorlds = document.getElementsByClassName('hello')
// => [ <p class='hello'>hello world 1</p>,
// <p class='hello'>hello world 2</p>,
// <p class='hello'>hello world 3</p>,
// <p class='hello'>hello world 4</p> ]
<html>
<body>
<div class='parent'>
<p class='hello'>hello world 1</p>
<p class='hello'>hello world 2</p>
<p class='hello'>hello world 3</p>
<p class='hello'>hello world 4</p>
</div>
</body>
</html>
function getElementsByClassName2(classNameStr) {
const elements = [] // the array we will add matching elements to
const firstChildren = this.children // all the children of the element the function is called on
return elements
}
@shanelonergan
shanelonergan / streak-tracker.rb
Last active February 9, 2022 01:01
Example code for tracker number of consecutive days a User performs a Session
class User < ApplicationRecord
has_many :sessions, -> {order "created_at DESC"}
def streak
streak_count = 0
today = Time.now.to_date
dates_array = self.sessions.map do | session |
session.created_at.to_date