Skip to content

Instantly share code, notes, and snippets.

View aaronvegu's full-sized avatar
🐢
Coding

Aaron Vegu aaronvegu

🐢
Coding
View GitHub Profile
@aaronvegu
aaronvegu / dogFactory.js
Created January 6, 2021 19:11
Create a kind of basic object constructor with properties, methods, setters and getters in JS.
// Constructor
function dogFactory(name, breed, weight) {
return {
// Object Properties
_name: name,
_breed: breed,
_weight: weight,
// Setter & Getters
get name() {
/**
* Write a function sortSpeciesByTeeth() that takes in an array of species objects in the format:
* {speciesName: 'shark', numTeeth: 50 }
* and sorts the array in ascending order based on the average number of teeth that species possesses (numTeeth).
*/
const speciesArray = [ {speciesName:'shark', numTeeth:50}, {speciesName:'dog', numTeeth:42}, {speciesName:'alligator', numTeeth:80}, {speciesName:'human', numTeeth:32}];
const sortSpeciesByTeeth = arr => {
return arr.sort((a, b) => a.numTeeth > b.numTeeth);
@aaronvegu
aaronvegu / js-object-methods.js
Created December 31, 2020 05:49
Short explication about the usage and creation of functions inside js objects, also called Object Methods. Not my content: Taken from codecademy.
/**
* JavaScript objects may have property values that are functions. These are referred to as object methods.
* Methods may be defined using anonymous arrow function expressions, or with shorthand method syntax.
* Object methods are invoked with the syntax: objectName.methodName(arguments).
*/
const engine = {
// method shorthand, with one argument
start(adverb) {
console.log(`The engine starts up ${adverb}...`);
@aaronvegu
aaronvegu / passing-js-objects.js
Created December 31, 2020 05:44
When JavaScript objects are passed as arguments to functions or methods, they are passed by reference, not by value. This means that the object itself (not a copy) is accessible and mutable (can be changed) inside that function. Not my content: Taken from Codecademy
const origNum = 8;
const origObj = {color: 'blue'};
const changeItUp = (num, obj) => {
num = 7;
obj.color = 'red';
};
changeItUp(origNum, origObj);
@aaronvegu
aaronvegu / js-iterators.md
Created December 30, 2020 20:07
JavaScript basic iterators methods review

.forEach()

is used to execute the same code on every element in an array but does not change the array and returns undefined.

.map()

executes the same code on every element in an array and returns a new array with the updated elements.

.filter()

checks every element in an array to see if it meets certain criteria and returns a new array with the elements that return truthy for the criteria.

.findIndex()

@aaronvegu
aaronvegu / team-stats.js
Created December 28, 2020 15:28
Exercise taken from Codecademy Pro to practice basic data structures like arrays and objects.
// Exercise taken from Codecademy Pro to practice basic data structures like arrays and objects
const team = {
_players: [
{
firstName: 'Raul',
lastName: 'Gudino',
age: 23
},
{
// Exercise taken from Codecademy Pro to understand Object Sintax.
/**
* As a frequent diner, you love trying out new restaurants and experimenting with different foods.
* However, having to figure out what you want to order can be a time-consuming ordeal if the menu is big,
* and you want an easier way to be able to figure out what you are going to eat.
* In this project, you’ll use JavaScript to randomly create a three-course meal based on what is available on a menu.
* We’ll keep running it until we’re satisfied with the generated meal!
*/
const menu = {
let input = 'I like turtles!'
const vowels = ['a', 'e', 'i', 'o', 'u']
let resultArray = []
let word = ''
for (let i = 0; i < input.length; i++) {
for (let j = 0; j < vowels.length; j++) {
let target;
const humanGuessInput = document.getElementById('human-guess');
const roundNumberDisplay = document.getElementById('round-number');
const computerGuessDisplay = document.getElementById('computer-guess');
const humanScoreDisplay = document.getElementById('human-score');
const computerScoreDisplay = document.getElementById('computer-score');
const targetNumberDisplay = document.getElementById('target-number');
@aaronvegu
aaronvegu / Accesing the Process Object [NODE].md
Created November 28, 2020 22:10
Exercise to learn the basics of the Process Object on NodeJS. Take it from a Codecademy lesson.

Accessing the Process Object

In computer science, a process is the instance of a computer program that is being executed. You can open Task Manager if you’re on a Windows machine or Activity Monitor from a Mac to see information about the various processes running on your computer right now. Node has a global process object with useful methods and information about the current process.

The process.env property is an object which stores and controls information about the environment in which the process is currently running. For example, the process.env object contains a PWD property which holds a string with the directory in which the current process is located. It can be useful to have some if/else logic in a program depending on the current environment— a web application in a development phase might perform different tasks than when it’s live to users. We could store this information on the process.env. One convention is to add a property to process.env with the key NODE_ENV and a value of either produ