Skip to content

Instantly share code, notes, and snippets.

@rafagarcia
rafagarcia / JS Quiz Answer Explanations.md
Created August 30, 2017 06:47 — forked from MattSurabian/JS Quiz Answer Explanations.md
My attempt to explain the answers for David Shariff's feelings hurting JS quiz found at: davidshariff.com/js-quiz/

Are your feelings hurt?

If you rushed through David Shariff's JS Quiz or are just new to JS they might be. I know mine were. After I dried my eyes, I took the quiz again, this time very slowly trying to get at the meat behind each answer. Below is my attempt to explain each question's answer and offer some interesting permutations so that others can move beyond their hurt feelings and come out the other side better JS developers.

I initially thought I'd turn this into a blog post but think it's probably better as a gist.

Question #1

Don't over think it.

var foo = function foo() {
@rafagarcia
rafagarcia / JS Quiz Answer Explanations.md
Created August 30, 2017 06:47 — forked from MattSurabian/JS Quiz Answer Explanations.md
My attempt to explain the answers for David Shariff's feelings hurting JS quiz found at: davidshariff.com/js-quiz/

Are your feelings hurt?

If you rushed through David Shariff's JS Quiz or are just new to JS they might be. I know mine were. After I dried my eyes, I took the quiz again, this time very slowly trying to get at the meat behind each answer. Below is my attempt to explain each question's answer and offer some interesting permutations so that others can move beyond their hurt feelings and come out the other side better JS developers.

I initially thought I'd turn this into a blog post but think it's probably better as a gist.

Question #1

Don't over think it.

var foo = function foo() {
@rafagarcia
rafagarcia / getEngineersAge.js
Created August 1, 2018 13:32
Little js katah
/* Dado el siguiente array de objetos, queremos que se muestre
en consola el valor agregado de las edades de todos los
empleados con el valor de position 'engineer'.
*/
let employees = [
{
'fullName': 'Andres Urquía',
'age': 25,
'position': 'engineer'
@rafagarcia
rafagarcia / jsbin.kejufac.js
Last active August 4, 2018 09:12
private-public-methods-exposure
var module = (function(){
/* simple método privado */
var privateMethod = function(){
console.log("soy un método privado");
};
/* retornando un objeto literal */
return{
publicMethod : function(){
privateMethod();
Hex Opacity Values
100% — FF
95% — F2
90% — E6
85% — D9
80% — CC
75% — BF
70% — B3
65% — A6
const numbers = [10, 20, 30, 40];
let updatedNumbers = numbers
.map((num) => num * 2)
.filter((num) => num > 50);
let doubledOver50 = numbers.reduce((finalList, num) => {
num = num * 2; //double each number (i.e. map)
//filter number > 50
if (num > 50) {
var cars = ['BMW','Benz', 'Benz', 'Tesla', 'BMW', 'Toyota'];
var carsObj = cars.reduce(function (obj, name) {
obj[name] = obj[name] ? ++obj[name] : 1;
return obj;
}, {});
console.log(carsObj);
// Destructuring with rest parameter
let {_internal, tooBig, ...cleanObject} = {el1: '1', _internal:"secret", tooBig:{}, el2: '2', el3: '3'};
console.log(cleanObject); // {el1: '1', el2: '2', el3: '3'}
// Destructuring nested object
var car = {
model: 'bmw 2018',
engine: {
v6: true,
turbo: true,
vin: 12345
}
}
// sets
let arr = [1, 1, 2, 2, 3, 3];
let deduped = [...new Set(arr)] // [1, 2, 3]
console.log(deduped);
let mySet = new Set([1,2, 3, 4, 5]);
var filtered = [...mySet].filter((x) => x > 3) // [4, 5]