-
Notifications
You must be signed in to change notification settings - Fork 18
finish home task #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
romanPashnitskyi
wants to merge
1
commit into
front-camp-2018:master
Choose a base branch
from
romanPashnitskyi:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
finish home task #10
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "presets": ["env"] | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| language: node_js | ||
| node_js: | ||
| - "lts/*" |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,50 @@ | ||
| export const dragonCurve = n => { | ||
| // logic... | ||
| let size = Math.pow(2, n); | ||
| let arr = []; | ||
| arr.length = --size; | ||
| arr = getDirections(n); | ||
| const result = Number(arr.join('')); | ||
|
|
||
| return result; | ||
| }; | ||
|
|
||
| const getDirections = number => { | ||
| let size = Math.pow(2, number); | ||
| const arr = []; | ||
| arr.length = --size; | ||
|
|
||
| if (number === 1) { | ||
| arr[0] = 1; | ||
| return arr; | ||
| } else { | ||
| let sizeOther = Math.pow(2, number - 1); | ||
| let arrOther = []; | ||
| arrOther.length = --sizeOther; | ||
| arrOther = getDirections(number - 1); | ||
|
|
||
| for (let i = 0; i < sizeOther; i++) { | ||
| arr[i] = arrOther[i]; | ||
| } | ||
|
|
||
| arr[sizeOther] = 1; | ||
|
|
||
| for (let i = 0; i < sizeOther; i++) { | ||
| if (arrOther[i] === 1) { | ||
| arrOther[i] = 0; | ||
| } else { | ||
| arrOther[i] = 1; | ||
| } | ||
| } | ||
|
|
||
| let index = 0; | ||
|
|
||
| for (let i = size - 1; i > size / 2; i--) { | ||
| arr[i] = arrOther[index]; | ||
| index++; | ||
| } | ||
|
|
||
| return arr; | ||
| } | ||
|
|
||
| }; | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,10 @@ | ||
| import {dragonCurve} from './index' | ||
| import {dragonCurve} from './index'; | ||
|
|
||
| describe('dragonCurve::', () => { | ||
| // need to implement | ||
| it('Should return number as is', () => { | ||
| expect(dragonCurve(1)).toEqual(1); | ||
| expect(dragonCurve(2)).toEqual(110); | ||
| expect(dragonCurve(3)).toEqual(1101100); | ||
| expect(dragonCurve(4)).toEqual(110110011100100); | ||
| }); | ||
| }); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,20 @@ | ||
| export const rotateMatrix = arr => { | ||
| // logic... | ||
| const width = arr.length || 0; | ||
| const height = arr[0] instanceof Array ? arr[0].length : 0; | ||
|
|
||
| if (height === 0 || width === 0) { | ||
| return []; | ||
| } | ||
|
|
||
| const transformation = []; | ||
|
|
||
| for (let i = 0; i < height; i++) { | ||
| transformation[i] = []; | ||
| for (let j = 0; j < width; j++) { | ||
| transformation[i][j] = arr[j][i]; | ||
| } | ||
| } | ||
|
|
||
| return transformation; | ||
| }; | ||
|
|
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,24 @@ | ||
| import {rotateMatrix} from './index' | ||
| import {rotateMatrix} from './index'; | ||
|
|
||
| describe('rotateMatrix::', () => { | ||
| // need to implement | ||
| const arr1 = [ | ||
| [1, 2], | ||
| [3, 4] | ||
| ]; | ||
| const arr2 = [ | ||
| [1, 2, 3], | ||
| [4, 5, 6], | ||
| [7, 8, 9] | ||
| ]; | ||
| it('Should return', () => { | ||
| expect(rotateMatrix(arr1)).toEqual([ | ||
| [1,3], | ||
| [2,4] | ||
| ]); | ||
| expect(rotateMatrix(arr2)).toEqual([ | ||
| [1,4,7], | ||
| [2,5,8], | ||
| [3,6,9] | ||
| ]); | ||
| }); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
дуже складна логіка!