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
// Just a normal function, not an async function. | |
function firstFunction(){ | |
return new Promise((resolve, reject)=> { | |
var randomNumber = (Math.floor(Math.random() * 100) % 2); | |
if(randomNumber === 0){ | |
setTimeout(() => { | |
resolve("Number is even"); | |
}, 3000); | |
}else { | |
setTimeout(() => { |
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
async function getData(url){ | |
const response = await fetch(url); | |
console.log(response); | |
} | |
getData('https://dog.ceo/api/breeds/image/random'); | |
getData('https://dog.ceo/api/breed/Husky/images/random'); |
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 callDogApi(url){ | |
const promise = fetch(url); | |
promise.then((response)=> { | |
if(response.status === 200){ | |
console.log('Api call successful'); | |
console.log(response); | |
}else{ | |
throw new Error(response.status); | |
} | |
}).catch((error)=> { |
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
async function myFirstAsyncFunction(){ | |
return "Hello" | |
} | |
myFirstAsyncFunction().then((result) => { | |
console.log(result); | |
}); | |
// Output | |
// Hello |
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 main(){ | |
console.log("I'll have my breakfast"); | |
setTimeout(() => { | |
console.log("I'll have my lunch"); | |
}, 0); | |
console.log("I'll have my dinner"); | |
} | |
main(); |
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
# == Schema Information | |
# | |
# Table name: accounts | |
# | |
# id :bigint not null, primary key | |
# balance :integer | |
# created_at :datetime not null | |
# updated_at :datetime not null | |
# |
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 Game | |
def play(matches) | |
matches.each do |match| | |
result = match.split(";") | |
first_team = Team.find_or_initialize(result[0]) | |
second_team = Team.find_or_initialize(result[1]) | |
outcome = result[2] | |
case outcome | |
when "win" | |
first_team.wins! |
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
module SuperPowers | |
def powers | |
puts "I can run at 80 mph and lift 200 lbs weight" | |
end | |
end | |
class Human | |
def introduce | |
puts "Hi i am a #{self.class.name}" | |
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
class Human | |
def introduce | |
puts "Hello I am a #{self.class.name}" | |
end | |
end | |
class SuperHuman < Human | |
include SuperPowers | |
include Enemies | |
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
class A | |
end | |
class B < A | |
end | |
class C < B | |
end | |
A.descendants |