Forked from egor-miasnikov/gist:a9b79587c4054c34cb05ddb7c52a0c5e
Last active
May 14, 2017 13:38
-
-
Save vvscode/629b29b349ffe483f2aa2393096878ea to your computer and use it in GitHub Desktop.
This file contains 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 { | |
buildSquareStr | |
} = require('./buildSquareStr'); | |
const assert = require('assert'); | |
const SQUARES = { | |
1: `■`, | |
3: [`□□□`, `□■□`, `□□□`].join('\n'), | |
5: [`■■■■■`, `■□□□■`, `■□■□■`, `■□□□■`, `■■■■■`].join('\n'), | |
7: ['□□□□□□□', '□■■■■■□', '□■□□□■□', '□■□■□■□', '□■□□□■□', '□■■■■■□', '□□□□□□□'].join('\n'), | |
9: [`■■■■■■■■■`, `■□□□□□□□■`, `■□■■■■■□■`, `■□■□□□■□■`, `■□■□■□■□■`, `■□■□□□■□■`, `■□■■■■■□■`, `■□□□□□□□■`, `■■■■■■■■■`].join('\n'), | |
25: [`■■■■■■■■■■■■■■■■■■■■■■■■■`, `■□□□□□□□□□□□□□□□□□□□□□□□■`, `■□■■■■■■■■■■■■■■■■■■■■■□■`, `■□■□□□□□□□□□□□□□□□□□□□■□■`, `■□■□■■■■■■■■■■■■■■■■■□■□■`, `■□■□■□□□□□□□□□□□□□□□■□■□■`, `■□■□■□■■■■■■■■■■■■■□■□■□■`, `■□■□■□■□□□□□□□□□□□■□■□■□■`, `■□■□■□■□■■■■■■■■■□■□■□■□■`, `■□■□■□■□■□□□□□□□■□■□■□■□■`, `■□■□■□■□■□■■■■■□■□■□■□■□■`, `■□■□■□■□■□■□□□■□■□■□■□■□■`, `■□■□■□■□■□■□■□■□■□■□■□■□■`, `■□■□■□■□■□■□□□■□■□■□■□■□■`, `■□■□■□■□■□■■■■■□■□■□■□■□■`, `■□■□■□■□■□□□□□□□■□■□■□■□■`, `■□■□■□■□■■■■■■■■■□■□■□■□■`, `■□■□■□■□□□□□□□□□□□■□■□■□■`, `■□■□■□■■■■■■■■■■■■■□■□■□■`, `■□■□■□□□□□□□□□□□□□□□■□■□■`, `■□■□■■■■■■■■■■■■■■■■■□■□■`, `■□■□□□□□□□□□□□□□□□□□□□■□■`, `■□■■■■■■■■■■■■■■■■■■■■■□■`, `■□□□□□□□□□□□□□□□□□□□□□□□■`, `■■■■■■■■■■■■■■■■■■■■■■■■■`].join('\n'), | |
}; | |
describe('buildSquareStr', () => { | |
it('buildSquareStr is a function', () => assert.equal(typeof buildSquareStr, 'function')); | |
Object.keys(SQUARES) | |
.forEach((x) => it(`should return correct square for ${x}`, | |
() => assert.equal(buildSquareStr(+x), SQUARES[x], `it should be ${SQUARES[x]}`))); | |
}); |
This file contains 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 SQUARE_TYPES = { | |
'□': '■', | |
'■': '□', | |
}; | |
const wrapSquare = (square, wrapper) => { | |
let edgeLine = (new Array(square[0].length + 2)).fill(wrapper).join(''); | |
return [ | |
edgeLine, | |
...square.map((line) => `${wrapper}${line}${wrapper}`), | |
edgeLine, | |
]; | |
} | |
const buildSquare = (x) => { | |
if (x === 1) { | |
return [SQUARE_TYPES[Object.keys(SQUARE_TYPES)[0]]]; | |
} | |
let innerSquare = buildSquare(x - 2); | |
let lastWrapperOfInnerSquare = innerSquare[0][0]; | |
let wrapper = SQUARE_TYPES[lastWrapperOfInnerSquare]; | |
let wrappedSquare = wrapSquare(innerSquare, wrapper); | |
return wrappedSquare; | |
} | |
const buildSquareStr = (x, squareType = `black`) => { | |
return buildSquare(x, squareType).join('\n'); | |
}; | |
module.exports = { | |
buildSquareStr | |
} |
This file contains 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
# Задание: | |
Заполните шаблон, используя специальные символы - ■ □ | |
А в этом задании давайте нарисуем квадрат с эффектом масштабирования. | |
# Правила: | |
Параметр n: длина стороны квадрата, которая всегда должна быть положительным нечетным числом. | |
Возвращаемое значение это строковый квадрат, который состоит из чередующихся символов ■ и □. | |
А каждая строка разделяется символом «\n». | |
# Пример: | |
zoom(1) | |
■ | |
zoom(3) | |
□□□ | |
□■□ | |
□□□ | |
zoom(5) | |
■■■■■ | |
■□□□■ | |
■□■□■ | |
■□□□■ | |
■■■■■ | |
zoom(7) | |
□□□□□□□ | |
□■■■■■□ | |
□■□□□■□ | |
□■□■□■□ | |
□■□□□■□ | |
□■■■■■□ | |
□□□□□□□ | |
zoom(9) | |
■■■■■■■■■ | |
■□□□□□□□■ | |
■□■■■■■□■ | |
■□■□□□■□■ | |
■□■□■□■□■ | |
■□■□□□■□■ | |
■□■■■■■□■ | |
■□□□□□□□■ | |
■■■■■■■■■ | |
zoom(25) | |
■■■■■■■■■■■■■■■■■■■■■■■■■ | |
■□□□□□□□□□□□□□□□□□□□□□□□■ | |
■□■■■■■■■■■■■■■■■■■■■■■□■ | |
■□■□□□□□□□□□□□□□□□□□□□■□■ | |
■□■□■■■■■■■■■■■■■■■■■□■□■ | |
■□■□■□□□□□□□□□□□□□□□■□■□■ | |
■□■□■□■■■■■■■■■■■■■□■□■□■ | |
■□■□■□■□□□□□□□□□□□■□■□■□■ | |
■□■□■□■□■■■■■■■■■□■□■□■□■ | |
■□■□■□■□■□□□□□□□■□■□■□■□■ | |
■□■□■□■□■□■■■■■□■□■□■□■□■ | |
■□■□■□■□■□■□□□■□■□■□■□■□■ | |
■□■□■□■□■□■□■□■□■□■□■□■□■ | |
■□■□■□■□■□■□□□■□■□■□■□■□■ | |
■□■□■□■□■□■■■■■□■□■□■□■□■ | |
■□■□■□■□■□□□□□□□■□■□■□■□■ | |
■□■□■□■□■■■■■■■■■□■□■□■□■ | |
■□■□■□■□□□□□□□□□□□■□■□■□■ | |
■□■□■□■■■■■■■■■■■■■□■□■□■ | |
■□■□■□□□□□□□□□□□□□□□■□■□■ | |
■□■□■■■■■■■■■■■■■■■■■□■□■ | |
■□■□□□□□□□□□□□□□□□□□□□■□■ | |
■□■■■■■■■■■■■■■■■■■■■■■□■ | |
■□□□□□□□□□□□□□□□□□□□□□□□■ | |
■■■■■■■■■■■■■■■■■■■■■■■■■ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment