JavaScript
31.4K subscribers
1.2K photos
10 videos
33 files
871 links
A resourceful newsletter featuring the latest and most important news, articles, books and updates in the world of #javascript 🚀 Don't miss our Quizzes!

Let's chat: @nairihar
Download Telegram
CHALLENGE

function highlight(strings, ...values) {
return strings.reduce((result, str, i) => {
const value = values[i - 1];
const transformed =
typeof value === "number"
? `[${value * 2}]`
: `(${String(value).toUpperCase()})`;
return result + transformed + str;
});
}

const product = "widget";
const qty = 4;
const price = 12.5;

const output = highlight`Order: ${product} x${qty} @ $${price}`;
console.log(output);
2
CHALLENGE

function* pipeline(...fns) {
let value = yield;
for (const fn of fns) {
value = yield fn(value);
}
return value;
}

const double = x => x * 2;
const addTen = x => x + 10;
const square = x => x * x;

const gen = pipeline(double, addTen, square);

gen.next(); // prime the generator
const r1 = gen.next(3);
const r2 = gen.next(r1.value);
const r3 = gen.next(r2.value);

console.log(r1.value, r2.value, r3.value);
What is the output?
Anonymous Quiz
24%
6 16 196
24%
3 13 169
50%
6 16 256
3%
3 16 256