Skip to content

Instantly share code, notes, and snippets.

View anthonymjimenez's full-sized avatar

Anthony Jimenez anthonymjimenez

View GitHub Profile
@anthonymjimenez
anthonymjimenez / typeError.js
Created November 24, 2020 03:50
Proto example with instance.property
const instance = new Trip(["Boston", "Salem"], 600, 6);
console.log(instance.durationInHours()) // => 144 hours
console.log(instance.destination.durationInHours()) // TypeError:
// instance.destination.durationInHours is not a function
@anthonymjimenez
anthonymjimenez / classTrip.js
Last active November 24, 2020 03:53
instance of basic
class Trip {
constructor(destination, budget, passports) {
this.destination = destination;
(this.budget = budget), (this.duration = 6);
}
durationInHours() {
return `${24 * this.duration} hours`
}
}
@anthonymjimenez
anthonymjimenez / nonConfigDelete.js
Last active November 24, 2020 00:14
non config delete
let myTrip = {
location: "Boston",
budget: 600,
passports: true
}
Object.defineProperty(myTrip, 'passports', {configurable: false} )
function deleteProperty(object, property) {
@anthonymjimenez
anthonymjimenez / deleteMethods.js
Created November 23, 2020 22:02
myTrip with method
const myTrip = {
location: "Boston",
budget: 600,
duration: function(arg) { return arg }
}
function deleteProperty(object, property) {
return delete object[property]
}
@anthonymjimenez
anthonymjimenez / deletePrimType.js
Created November 23, 2020 21:36
delete with global vars
const hello = 'hello'
goodbye = 'goodbye'
console.log(delete hello) // false
console.log(delete goodbye) // true
console.log(hello, goodbye=undefined) // hello undefined
@anthonymjimenez
anthonymjimenez / delete.js
Last active November 23, 2020 22:01
Delete
const myTrip = {
location: "Boston",
budget: 600,
duration: function(arg) { return arg }
}
function deleteProperty(object, property) {
return delete object[property]
}
@anthonymjimenez
anthonymjimenez / locateGrade.js
Created November 9, 2020 18:30
locate grade
function locateGrade(objStudent, error) {
let student = objStudent.student;
if (!student) return error.error_message;
const quiz_grades =
student.quiz_grades !== undefined ? student.quiz_grades : [0, 0, 0];
const test_grades =
objStudent.student.test_grades !== undefined ? student.test_grades : [0, 0];
const extra_credit =
student.extraCredit !== undefined ? student.extra_credit : 0;
return [...quiz_grades, ...test_grades, extra_credit];
@anthonymjimenez
anthonymjimenez / extractGrades.js
Last active April 28, 2021 05:18
Extract Grades
const error = {
error_message: "Student not found",
};
const objStudent = {
student: {
name: "Anthony",
quiz_grades: [10, 9, 7],
test_grades: [7, 8],
extra_credit: undefined,
@anthonymjimenez
anthonymjimenez / obj.js
Last active November 9, 2020 18:03
obj
let nestObject = {
arrayOfObjects: [
{
one: 1,
two: 2,
three: 3,
},
{
restOfNumbers: [{four: 4}, {five: 5}, 6, 7, 8, 9, 10],
},
@anthonymjimenez
anthonymjimenez / objectsInDepth.js
Created November 9, 2020 16:11
objects in depth destructing
let numbers = { numbers: { one: 1 } };
const {
numbers: { one },
} = numbers;
console.log(one); // 1
const {
numbers: { one: numberOne },