๐4โค1
Please open Telegram to view this post
VIEW IN TELEGRAM
๐คฃ24โค3๐3๐ฅ3
CHALLENGE
const engine = {
type: "V8",
displacement: 4.0,
getInfo() {
return `${this.type} - ${this.displacement}L`;
},
turbo: {
boost: 12,
getBoost() {
return `${this.type ?? "Unknown"} boosted at ${this.boost} psi`;
},
},
};
const detached = engine.getInfo;
const turboInfo = engine.turbo.getBoost;
console.log(engine.getInfo());
console.log(engine.turbo.getBoost());
console.log(turboInfo());๐ฅ5โค4
What is the output?
Anonymous Quiz
21%
V8 - 4L Unknown boosted at 12 psi Unknown boosted at undefined psi
26%
V8 - 4.0L Unknown boosted at 12 psi V8 boosted at 12 psi
33%
V8 - 4.0L V8 boosted at 12 psi Undefined boosted at 12 psi
20%
V8 - 4.0L Unknown boosted at 12 psi Unknown boosted at undefined psi
๐3โค1
CHALLENGE
const product = {
name: "Laptop",
price: 1299,
stock: 42,
discount: 0,
category: "Electronics",
};
const filtered = Object.entries(product)
.filter(([key, value]) => Boolean(value))
.reduce((acc, [key, value]) => {
acc[key] = value;
return acc;
}, {});
console.log(Object.keys(filtered).length);
console.log(Object.values(filtered).includes(0));
console.log(Object.keys(filtered).join(", "));๐4๐ฅ1
What is the output?
Anonymous Quiz
28%
5 true name, price, stock, discount, category
27%
4 true name, price, stock, category
16%
3 false name, price, category
30%
4 false name, price, stock, category
โค6๐คฃ1
CHALLENGE
const transactions = [
{ id: 1, type: "credit", amount: 200 },
{ id: 2, type: "debit", amount: 50 },
{ id: 3, type: "credit", amount: 150 },
{ id: 4, type: "debit", amount: 30 },
{ id: 5, type: "credit", amount: 100 },
];
const result = transactions
.filter(tx => tx.type === "credit")
.map(tx => ({ ...tx, amount: tx.amount * 1.1 }))
.reduce((acc, tx) => acc + tx.amount, 0);
console.log(result.toFixed(2));
๐ฅ3
โค4๐ฅ1๐ค1
CHALLENGE
class AppError extends Error {
constructor(message, code) {
super(message);
this.name = "AppError";
this.code = code;
}
}
function riskyOperation(value) {
if (value === null) throw new AppError("Null value", 404);
if (typeof value !== "number") throw new TypeError("Not a number");
if (value < 0) throw new RangeError("Negative value");
return value * 2;
}
const inputs = [42, null, "hello", -5];
const results = inputs.map((input) => {
try {
return riskyOperation(input);
} catch (err) {
if (err instanceof AppError) return `AppError:${err.code}`;
if (err instanceof TypeError) return `TypeError`;
if (err instanceof RangeError) return `RangeError`;
return `UnknownError`;
}
});
console.log(results);โค2๐2๐ฅ1
After a long experimental phase, Solid 2.0โs first beta lands with first-class async support where computations can return Promises or async iterables, and the reactive graph suspends and resumes around them natively. <Suspense> is retired in favor of <Loading> for initial renders, and mutations get a first-class action() primitive with optimistic support. For existing users the breaking changes are substantial, but thereโs a migration guide.
Ryan Carniato
Please open Telegram to view this post
VIEW IN TELEGRAM
๐5โค4๐ฅ4
CHALLENGE
const inventory = {
apples: 5,
bananas: 12,
cherries: 0,
dates: 8,
};
const result = Object.entries(inventory)
.filter(([_, qty]) => qty > 0)
.reduce((acc, [fruit, qty]) => {
acc[fruit] = qty * 2;
return acc;
}, {});
const keys = Object.keys(result);
const values = Object.values(result);
console.log(keys.length, values.reduce((sum, v) => sum + v, 0));๐5โค2๐ฅ2
100๐5โค1
CHALLENGE
const handler = {
get(target, prop, receiver) {
if (prop === 'fullName') {
return `${Reflect.get(target, 'firstName', receiver)} ${Reflect.get(target, 'lastName', receiver)}`;
}
return Reflect.get(target, prop, receiver);
},
set(target, prop, value, receiver) {
if (typeof value !== 'string') {
return false;
}
return Reflect.set(target, prop, value.trim(), receiver);
},
has(target, prop) {
return prop.startsWith('_') ? false : Reflect.has(target, prop);
}
};
const person = new Proxy({ firstName: ' Clara', lastName: 'Oswald ', _secret: 'hidden' }, handler);
person.firstName = ' Clara';
person.lastName = ' Oswald';
console.log(person.fullName);
console.log('_secret' in person);
console.log(Reflect.ownKeys(person).length);
๐ฅ7โค4๐2๐ค2
What is the output?
Anonymous Quiz
16%
Clara Oswald false 3
50%
Clara Oswald false 3
25%
Clara Oswald false 2
9%
Clara Oswald true 3
๐ฅ4๐2โค1
CHALLENGE
const str = "JavaScript is Awesome!";
const result = str
.split(" ")
.map((word, i) => {
if (i % 2 === 0) return word.toUpperCase();
return word.toLowerCase();
})
.map((word) => [...word].reverse().join(""))
.join("-");
console.log(result);
โค8๐2๐ฅ1
What is the output?
Anonymous Quiz
19%
tpircsavaj-SI-!emosewa
53%
TPIRCSAVAJ-si-!EMOSEWA
21%
TPIRCSAVAJ-is-!EMOSEWA
6%
TPIRCSVAJ-si-EMOSEWA!
โค3๐ฅ2
CHALLENGE
const person = { name: "Carlos", scores: [10, 20, 30] };
const clone = { ...person };
clone.name = "Diana";
clone.scores.push(40);
const snapshot = Object.assign({}, person);
snapshot.name = "Elena";
snapshot.scores.push(50);
console.log(person.name);
console.log(person.scores.length);
console.log(clone.name);
console.log(clone.scores === person.scores);
๐ฅ3๐2โค1
What is the output?
Anonymous Quiz
27%
Carlos 5 Diana true
28%
Carlos 4 Diana false
35%
Carlos 3 Diana false
10%
Diana 5 Diana true
โค2๐2๐ค1