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 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 |
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
| 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 | |
| } |
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
| <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> |
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 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> ] |
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
| function getElementsByClassName2(classNameStr) { | |
| const elements = [] | |
| const firstChildren = this.children | |
| function checkChildren(child) { | |
| if (child.classList.contains(classNameStr)) { | |
| elements.push(child) | |
| } |
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
| 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 |
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
| HTMLElement.prototype.getElementsByClassname2 = getElementsByClassName2 |
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
| Time.now.to_date | |
| => 2019-10-15 |
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
| Time.now | |
| => 2019-10-15 16:16:16 -0400 |
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
| unique_dates = dates_array.uniq | |
OlderNewer