Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
presets: ['@babel/preset-env'],
};
13,645 changes: 13,645 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
"html-webpack-plugin": "^3.2.0",
"husky": "^1.1.2",
"jest": "^23.6.0",
"@babel/core": "*",
"@babel/preset-env": "*",
"babel-core": "7.0.0-bridge.0",
"babel-jest": "*",
"node-sass": "^4.9.4",
"sass-loader": "^7.1.0",
"style-loader": "^0.23.1",
Expand Down
29 changes: 27 additions & 2 deletions src/dragon-curve/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
export const dragonCurve = n => {
// logic...
};
let curve = '1';
let counter = n;

function getDragonCurve () {
if (counter > 1) {
counter--;

const str = getDragonCurve(n - 1);
curve += `1${flipAndReverse(str)}`;
}

return curve;
}

function flipAndReverse (str) {
if (str) {

return str
.split('')
.map(value => parseInt(value, 10) === 1 ? 0 : 1)
.reverse()
.join('');
}
}

return getDragonCurve();
};
22 changes: 20 additions & 2 deletions src/dragon-curve/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
import {dragonCurve} from './index'
import {dragonCurve} from './index';

describe('dragonCurve::', () => {
// need to implement
it('Shoult return a dragon curve for the number 1', () => {
expect(dragonCurve(1)).toBe('1');
});

it('Shoult return a dragon curve for the number 2', () => {
expect(dragonCurve(2)).toBe('110');
});

it('Shoult return a dragon curve for the number 3', () => {
expect(dragonCurve(3)).toBe('1101100');
});

it('Shoult return a dragon curve for the number 4', () => {
expect(dragonCurve(4)).toBe('110110011100100');
});

it('Shoult return a dragon curve for the number 5', () => {
expect(dragonCurve(5)).toBe('1101100111001001110110001100100');
});
});
11 changes: 9 additions & 2 deletions src/rotate-matrix/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
export const rotateMatrix = arr => {
// logic...
};
const resultArr = arr.map(() => []);

arr.forEach(outerItem => {
outerItem.forEach((innerItem, innerIndex) => {
resultArr[innerIndex].push(innerItem);
});
});

return resultArr;
};
38 changes: 36 additions & 2 deletions src/rotate-matrix/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,39 @@
import {rotateMatrix} from './index'
import {rotateMatrix} from './index';

describe('rotateMatrix::', () => {
// need to implement
it('Should transform an array 2x2 by replacing its values', () => {
expect(rotateMatrix([
[1, 2],
[3, 4] ]
)).toEqual([
[1, 3],
[2, 4]
]);
});

it('Should transform an array 3x3 by replacing its values', () => {
expect(rotateMatrix([
[1,2,3],
[4,5,6],
[7,8,9]
])).toEqual([
[1,4,7],
[2,5,8],
[3,6,9]
]);
});

it('Should transform an array 4x4 by replacing its values', () => {
expect(rotateMatrix([
[1,2,3,4],
[5,6,7,8],
[9,10,11,12],
[13,14,15,16]
])).toEqual([
[1,5,9,13],
[2,6,10,14],
[3,7,11,15],
[4,8,12,16]
]);
});
});