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
function makePyramid(height) { | |
if (typeof height !== 'number' && height < 1) throw 'Wrong number'; | |
// Total number in pyramid is qual height^2 | |
const total = Math.pow(height, 2); | |
// make 2d array filled 0 | |
// each internal array length qual number of block in this pyramid leyer | |
let output = Array.from( | |
{ length: height}, | |
(_, i) => Array.from({ length: 2*(i+1) - 1}).fill(0) |
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 isHorseMove = str => { | |
if(!/^[A-H][1-8]-[A-H][1-8]$/.test(str)) throw new Error('wrong incoming data'); | |
// (c1, r1) - start coodinate, (c2, r2) - coordinate after move a figure | |
const [c1, r1, _, c2, r2] = str.split('').map(ch => ch.charCodeAt(0)); | |
return ( | |
(Math.abs(c1 - c2) === 1 && Math.abs(r1 - r2) === 2) | |
|| |
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
/** Для положительных k, за исключением 2, наименьшим числом n, | |
* является последний член арифметической прогрессии(АП), | |
* для которой k лежит в диаппазоне | |
* (предыдущая сумма прогрессии < k <= сумма прогрессии). | |
* Исходя из условия задачи, что n >= 1 следует, что k >= 1. | |
* Сложность алгоритма: O(n); | |
*/ | |
const validateAgrument = (k) => { | |
if (typeof k !== 'number') throw new Error('agument must be a number'); |