Skip to content

Instantly share code, notes, and snippets.

@lomeat
Created October 24, 2021 14:36
Show Gist options
  • Save lomeat/2919e87ac438690391504661d6748045 to your computer and use it in GitHub Desktop.
Save lomeat/2919e87ac438690391504661d6748045 to your computer and use it in GitHub Desktop.
soltion for r task
// Функции для проверки матриц
const devBy2 = (a) => a % 2 === 0;
const devBy5 = (a) => a % 5 === 0;
const ost5By2 = (a) => (a / 5) % 2 === 0;
const mult3By4 = (a) => (a * 3) % 4 === 0;
// Собрал все условия в массив для удобства работы с ними далее
// Можно изначально вынести их в отдельных объект, если
// в задаче предполагается, что условий может быть бесконечное множество
const conditions = [devBy2, devBy5, ost5By2, mult3By4];
// Возвращает пустую матрицу любых размеров
const getArray = (length) => Array.from({ length });
// Возвращает матрицу любых размеров, в которой числа идут по возрастанию
const getMatrix = (length) => getArray(length).map((_, index) => index + 1);
// Возвращает матрицу, которая является
// результатом проверки значений матрицы на определенное условие
const getMatrixByCondition = (conditionFunc, length) =>
getMatrix(length).filter(conditionFunc);
// Возвращает массив матриц, размер которого зависит от количества условий
// Так же можно указать изначальный размер матрицы (любое число)
const getResult = (length) =>
getArray(conditions.length).map((_, index) =>
getMatrixByCondition(conditions[index], length)
);
console.log(getResult(16));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment