var arr=[1,2,3,4,5];
console.log(arr.map((prev,curr)=>prev+curr));
console.log(arr.reduce((a,b)=>a+b));
console.log(arr.filter((a,b)=> (a + b) <= 5));
Ответ:
15
[ 1, 2, 3 ]
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
const users = [
{ id: 1, name: 'Alice' },
{ id: 2, name: 'Bob' },
{ id: 3, name: 'Charlie' }
];
const userScores = new WeakMap();
// Set scores for users
userScores.set(users[0], 95);
userScores.set(users[1], 80);
// Remove reference to Bob
users[1] = null;
let sum = 0;
for (const user of users) {
if (user && userScores.has(user)) {
sum += userScores.get(user);
}
}
console.log(sum);
Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
const wm = new WeakMap();
const obj1 = { name: 'first' };
const obj2 = { name: 'second' };
wm.set(obj1, 'value1');
wm.set(obj2, 'value2');
const keys = [];
for (let key of wm) {
keys.push(key);
}
console.log(keys.length);
console.log(wm.has(obj1));
console.log(wm.get(obj2));
console.log(sum);
Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
class DataProcessor {
constructor(value) {
this.value = value;
}
transform(fn) {
return new DataProcessor(fn(this.value));
}
getValue() {
return this.value;
}
}
const multiply = x => x * 2;
const add = x => x + 10;
const square = x => x * x;
const result = new DataProcessor(5)
.transform(multiply)
.transform(add)
.transform(square)
.getValue();
console.log(result);
Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
const target = { name: 'Sarah', age: 25 };
const handler = {
get(obj, prop) {
if (prop === 'info') {
return `${obj.name} is ${obj.age}`;
}
return Reflect.get(obj, prop);
},
has(obj, prop) {
return prop !== 'age' && Reflect.has(obj, prop);
}
};
const proxy = new Proxy(target, handler);
console.log(proxy.info);
console.log('age' in proxy);
console.log('name' in proxy);
Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
const products = [
{ id: 1, name: 'Laptop', price: 1200, category: 'Electronics' },
{ id: 2, name: 'Headphones', price: 100, category: 'Electronics' },
{ id: 3, name: 'Book', price: 15, category: 'Books' },
{ id: 4, name: 'Shirt', price: 25, category: 'Clothing' },
{ id: 5, name: 'Coffee Mug', price: 10, category: 'Kitchen' }
];
const result = products
.filter(p => p.price > 20)
.map(p => ({ name: p.name, value: p.price * 0.9 }))
.reduce((acc, item) => {
acc.names.push(item.name);
acc.total += item.value;
return acc;
}, { names: [], total: 0 });
console.log(result);
Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
console.log('1');
setTimeout(() => console.log('2'), 0);
Promise.resolve().then(() => console.log('3'));
queueMicrotask(() => console.log('4'));
setTimeout(() => {
console.log('5');
Promise.resolve().then(() => console.log('6'));
}, 0);
console.log('7');
Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
function createCounter() {
let count = 0;
function increment() {
count++;
return count;
}
function decrement() {
count--;
return count;
}
return { increment, decrement, reset: () => count = 0 };
}
const counter = createCounter();
counter.increment();
counter.increment();
counter.decrement();
const { increment, reset } = counter;
increment();
reset();
increment();
console.log(counter.increment());
Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
function greet(name) {
return `Hello, ${name}!`;
}
function highlight(strings, ...values) {
return strings.reduce((result, str, i) => {
return result + str + (values[i] ? `<em>${values[i]}</em>` : '');
}, '');
}
const user = 'Sarah';
const status = 'online';
console.log(highlight`User ${user} is currently ${status}.`);
Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
function createCounter() {
let count = 0;
return {
increment() {
count++;
return count;
},
getCount() {
return count;
}
};
}
const counter = createCounter();
console.log(counter.increment());
console.log(counter.getCount());
console.log(counter.increment());
console.log(counter.getCount());
Ответ:
Please open Telegram to view this post
VIEW IN TELEGRAM
const sym1 = Symbol('test');
const sym2 = Symbol('test');
const obj = {
[sym1]: 'first',
[sym2]: 'second',
regular: 'third'
};
const keys = Object.keys(obj);
const symbols = Object.getOwnPropertySymbols(obj);
const allProps = Reflect.ownKeys(obj);
console.log(keys.length);
console.log(symbols.length);
console.log(allProps.length);
console.log(sym1 === sym2);
Ответ:
Please open Telegram to view this post
VIEW IN TELEGRAM
var a = 0, b = 0, arr = [3, 6, 9, 6, 9, 3];
var data = arr.some((x, i)=>{
a = arr[i];
b = arr[i + 1];
return a + b == 15
})
console.log(data)
console.log(a, b)
Ответ:
6 9
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
function createCounter() {
let count = 0;
return {
increment: () => ++count,
decrement: () => --count,
get: () => count
};
}
const counter1 = createCounter();
const counter2 = createCounter();
counter1.increment();
counter1.increment();
counter2.increment();
console.log(counter1.get(), counter2.get());
const { increment, get } = counter1;
increment();
console.log(get());Ответ:
2 1 3
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
let a = 1;
setTimeout(() => {
a = 2;
}, 0);
console.log(a);
Ответ:
Please open Telegram to view this post
VIEW IN TELEGRAM
const Flyable = {
fly() { return 'flying'; }
};
const Swimmable = {
swim() { return 'swimming'; }
};
function applyMixins(target, ...mixins) {
mixins.forEach(mixin => {
Object.assign(target.prototype, mixin);
});
}
class Bird {}
class Fish {}
applyMixins(Bird, Flyable, Swimmable);
applyMixins(Fish, Swimmable);
const eagle = new Bird();
const shark = new Fish();
console.log(eagle.swim());
console.log(shark.fly?.() || 'undefined method');
Ответ:
Please open Telegram to view this post
VIEW IN TELEGRAM
console.log('1');
setTimeout(() => console.log('2'), 0);
Promise.resolve().then(() => console.log('3'));
setTimeout(() => console.log('4'), 0);
console.log('5');
Promise.resolve().then(() => {
console.log('6');
return Promise.resolve();
}).then(() => console.log('7'));
queueMicrotask(() => console.log('8'));
console.log('9');
Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
const data = [1, 2, 3, 4, 5];
const result = data.reduce((acc, val) => acc.concat(Array.from({ length: val }, (_, index) => val + index)), []);
console.log(result);
Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
Data Science: Зарабатывай на ИИ, пока другие просто играются с ним
ИИ стремительно меняет рынок и те, кто умеет работать с нейросетями, получают преимущество. Data Scientist — одна из самых высокооплачиваемых профессий: средняя зарплата от 100 000 ₽ уже на старте и кратный рост с опытом.
Для смотрящих в будущее подготовили бесплатный 4-дневный курс с полным разбором принципов работы ИИ, а также практикой создания своего собственного ИИ-проекта на Python.
Пройди тест, открой доступ к обучению и получи огромные возможности.
ИИ стремительно меняет рынок и те, кто умеет работать с нейросетями, получают преимущество. Data Scientist — одна из самых высокооплачиваемых профессий: средняя зарплата от 100 000 ₽ уже на старте и кратный рост с опытом.
Для смотрящих в будущее подготовили бесплатный 4-дневный курс с полным разбором принципов работы ИИ, а также практикой создания своего собственного ИИ-проекта на Python.
Пройди тест, открой доступ к обучению и получи огромные возможности.
const user = {
name: 'John',
age: 35,
};
for (const value in user) {
console.log(value);
}
Ответ:
age
Please open Telegram to view this post
VIEW IN TELEGRAM
function Person(name) {
this.name = name;
this.sayName = () => console.log(this.name);
}
const person1 = new Person('David');
const person2 = { name: 'Not David', sayName: person1.sayName };
person2.sayName();
Ответ:
Please open Telegram to view this post
VIEW IN TELEGRAM