Skip to content

Instantly share code, notes, and snippets.

View akaomy's full-sized avatar
🏍️

Anna K. akaomy

🏍️
View GitHub Profile
function Book(config) {
this.title = config.title;
this.author = config.author;
this.numPages = config.numPages;
this.currentPage = 0;
}
let newBook = {
title: "Robot Heart",
author: "J.K.",
@akaomy
akaomy / nested scope functions.js
Created April 17, 2019 02:34
Eloquent JS notes
// code inside ingrediend function can see the parameter of hummus function
// but outer - hummus function cannot see the inner bindings of ingredient function
const hummus = function(factor) {
const ingredient = function(amount, unit, name) {
let ingredientAmount = amount * factor;
if (ingredientAmount > 1) {
unit += "s";
}
console.log(`${ingredientAmount} ${unit} ${name}`);
};
@akaomy
akaomy / oop_js_basics.js
Last active February 28, 2019 06:58
cheatsheet of OOP JS BASICS
//To create an object(3):
//1)
var obj = new Object();
//2)
var obj = {};
//3)
a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
for i in a:
if i % 2 == 0 and i != 0:
print(i)
# Output:
# 2
# 4
# 6
webster = {
"Aardvark" : "A star of a popular children's cartoon show.",
"Baa" : "The sound a goat makes.",
"Carpet": "Goes on the floor.",
"Dab": "A small amount."
}
for i in webster:
print(webster[i])
start_list = [5, 3, 1, 2, 4]
square_list = []
for i in start_list:
test = i ** 2
square_list.append(test)
square_list.sort()
nums = [1,2,3,4,5,6,7,8,9,10]
my_list = []
for n in nums:
my_list.append(n)
print(my_list)
=>[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
my_list = [n for n in nums]
print(my_list)
=>[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
list = list()
list = list([2,3,4])
Traceback (most recent call last):
File "<input>", line 1, in <module>
TypeError: 'list' object is not callable
list = []
list.append(2)
list.append(3, 4)
Traceback (most recent call last):
NUMBER_OF_ELEMENTS = 5
numbers = []
sum = 0
for i in range(NUMBER_OF_ELEMENTS):
value = eval(input("Enter a new number: "))
numbers.append(value)
sum += value
average = sum / NUMBER_OF_ELEMENTS
def capitalizeEach(string):
print(" ".join(w.capitalize() for w in string.split()))
capitalizeEach("This is a loooog string")