This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const tasks = [ | |
{ id: 1, name: "Перевірити код", duration: 1000 }, | |
{ id: 2, name: "Написати звіт", duration: 2000 }, | |
{ id: 3, name: "Тестувати функцію", duration: 1500 } | |
]; | |
async function processTask(task) { | |
return new Promise((resolve) => { | |
setTimeout(() => { | |
const result = `${task.name} завершено за ${task.duration}мс`; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const tasks = [ | |
{ id: 1, name: "Перевірити код", duration: 1000 }, | |
{ id: 2, name: "Написати звіт", duration: 2000 }, | |
{ id: 3, name: "Тестувати функцію", duration: 1500 } | |
]; | |
function processTask(task) { | |
return new Promise((resolve) => { | |
setTimeout(() => { | |
const result = `${task.name} завершено за ${task.duration}мс`; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Уявімо, що у нас є список завдань (tasks), і кожне завдання потрібно "обробити" | |
// (наприклад, перевірити його статус) із певною затримкою, яка залежить від складності завдання. | |
// Ми хочемо обробити всі завдання послідовно й отримати результат. | |
const tasks = [ | |
{ id: 1, name: "Перевірити код", duration: 1000 }, | |
{ id: 2, name: "Написати звіт", duration: 2000 }, | |
{ id: 3, name: "Тестувати функцію", duration: 1500 } | |
]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Завдання наступне: є певна кількість задач, які потрібно виконати (tasks). | |
// Вони мають різну складність, визначену натуральним числом: від 1 до 20. | |
// В один день можна виконати лише ті задачі, складність яких відрізняється не більше, ніж на певне число (delta). | |
// Наприклад, якщо delta=3, то задачі зі складністю 5 можна виконати в один день лише із задачами, що >=2 та <=8. | |
// При цьому delta стосується усіх задач, що виконувалися в один день, а не лише двух останніх. | |
// Тобто, для delta=3, де перша задача дня має складність 8, друга 6, третя обмежена діапазоном від 5 до 9. | |
// (4 і 3 не підходять, бо вони відрізняються від 8 більше, ніж на 3 одиниці). | |
// | |
// Напишіть функцію, яка калькулює скільки днів потрібно на проходження всіх задач і має наступний вигляд: | |
// solution({ tasks: [array], delta: num, limit: null or num, sequential: bool }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Keyboard Shortcuts | |
*/ | |
// // File Navigation | |
// Ctrl + P - Quick file open | |
// Ctrl + Shift + P - Command palette | |
// Ctrl + B - Toggle sidebar |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Key principles: | |
- Write code that is easy to understand and maintain | |
- Follow consistent naming and formatting conventions | |
- Handle errors gracefully | |
- Use modern JavaScript features appropriately | |
- Consider performance implications | |
- Write testable code | |
- Keep your code DRY (Don't Repeat Yourself) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example 1: Counter | |
function makeCounter() { | |
let count = 0; | |
return function() { | |
return count++; | |
}; | |
} | |
let counter = makeCounter(); | |
console.log(counter()); // 0 |