Skip to content

Instantly share code, notes, and snippets.

View anthonymjimenez's full-sized avatar

Anthony Jimenez anthonymjimenez

View GitHub Profile
public class PlasticToyDuck implements ToyDuck {
@Override
public void squeak() {
System.out.println("Squeak squeak");
}
}
public class ToySparrow implements ToyBird {
public class PlasticToyDuck implements ToyDuck {
@Override
public void squeak() {
System.out.println("Squeak squeak");
}
}
public class ToySparrow implements ToyBird {
@anthonymjimenez
anthonymjimenez / finalDelete.js
Last active March 31, 2021 04:46
Final delete function
const arrayOfBuiltIns = [
Error,
Symbol,
Promise,
RegExp,
String,
Boolean,
Number,
Array,
Function,
@anthonymjimenez
anthonymjimenez / edgecasein.js
Last active November 25, 2020 20:46
Edge case In
class Trip {
constructor(destination, budget, duration) {
this.destination = destination;
(this.budget = budget), (this.duration = duration);
}
durationInHours() {
return `${24 * this.duration} hours`;
}
}
@anthonymjimenez
anthonymjimenez / addProperty.js
Created November 24, 2020 11:07
add property with in
let myTrip = {
destination: "Boston"
}
function findAndAddBudget(obj, argBudget) {
return ('budget' in obj) ? obj : {...obj, budget: argBudget}
}
console.log(myTrip) // { destination: 'Boston' }
myTrip = findAndAddBudget(myTrip, 600)
console.log(myTrip) // { destination: 'Boston', budget: 600 }
@anthonymjimenez
anthonymjimenez / deletewithtypeof.js
Created November 24, 2020 10:54
delete with type of
function instanceOf(instance, obj) {
return instance instanceof obj;
}
function deleteProperty(instance, property, userObject = null) {
if(typeof instance !== 'object') return `Primitive types like ${typeof instance} can not be deleted`
let arrayWithUserType = userObject
? [userObject, ...arrayOfBuiltIns]
: arrayOfBuiltIns;
let foundType = arrayWithUserType.find((builtInObj) =>
@anthonymjimenez
anthonymjimenez / edgetypeof.js
Last active November 24, 2020 10:39
edgecasestypeof
const newHello = new String('hello')
console.log(typeof newHello) // object
console.log(typeof []) // object
@anthonymjimenez
anthonymjimenez / instanceandtype.js
Created November 24, 2020 10:28
Instanceof typeof
const hello = 'hello'
const one = 1
console.log(hello instanceof String) // false
console.log(one instanceof Number) // false
console.log(typeof hello) // 'string'
console.log(typeof one) // 'number'
const newHello = new String('hello')
console.log(newHello instanceof Object) // true
@anthonymjimenez
anthonymjimenez / part2Delete.js
Last active November 24, 2020 04:52
Second form of delete function
const arrayOfBuiltIns = [
Error,
Promise,
RegExp,
String,
Boolean,
Number,
Array,
Function,
Object,
@anthonymjimenez
anthonymjimenez / typeErrorObj.js
Created November 24, 2020 03:55
Proto example with instance object
console.log(instance.destination.sort()) // => ['Boston', 'Salem']
console.log(instance.sort()) // TypeError: instance.sort is not a function