Публикации по теме 'toy-problems'


Кодовые войны - Сортировать лишнее (7кю)
Задача You have an array of numbers. Your task is to sort ascending odd numbers but even numbers must be on their places. Zero isn’t an odd number and you don’t need to move it. If you have an empty array, you need to return it. Пример sortArray([5, 3, 2, 8, 1, 4]) == [1, 3, 2, 8, 5, 4] Мое решение function sortArray(array) { const oddArr = []; const evenArr = []; const result = []; for (let i = 0; i < array.length; i += 1) { if (array[i]%2 === 0) {..

Кодовые войны - число простое? (6кю)
Задача Define a function that takes an integer argument and returns logical value true or false depending on if the integer is a prime. Per Wikipedia, a prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself. Пример is_prime(1) /* false */ is_prime(2) /* true */ is_prime(-1) /* false */ Первая попытка function isPrime(num) { if (num < 2) { return false; } for (let i = 2; i < (num / 2) + 1; i++) {..