-
Notifications
You must be signed in to change notification settings - Fork 212
Refactoring Process #68
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
zochasz
wants to merge
2
commits into
ironhack-labs:master
Choose a base branch
from
zochasz: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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 |
|---|---|---|
| @@ -1,33 +1,52 @@ | ||
| var ArrayFunctions = function (){} | ||
| class ArrayFunctions { | ||
| constructor(){ | ||
| this.array = []; | ||
|
|
||
| } | ||
| printSpecial(array) { | ||
| return array.join(" --- "); | ||
| }; | ||
|
|
||
| doubleArray(array){ | ||
| return array.map((number)=>{ | ||
| return number * 2; | ||
| }); | ||
| }; | ||
|
|
||
| superPower(array){ | ||
| return array.reduce((sum, number, index)=>{ | ||
| return sum + (number * (Math.pow(10, index))); | ||
| }); | ||
| } | ||
| } | ||
| module.exports = ArrayFunctions; | ||
|
|
||
| // 1) Define a function that takes an array with numbers and prints all the elements of the array, separated by " --- " | ||
| // ArrayFunctions.printSpecial([12, 33, 144, 122]) | ||
| // 12 -- 33 -- 144 -- 122 | ||
|
|
||
| ArrayFunctions.prototype.printSpecial = function (array) { | ||
| return array.join(" --- "); | ||
| }; | ||
| // ArrayFunctions.prototype.printSpecial = function (array) { | ||
| // return array.join(" --- "); | ||
| // }; | ||
|
|
||
| // 2) Define a function that takes an array with numbers and returns another array where each element contains double each element in the array | ||
| // ArrayFunctions.doubleMyArray([10, 20, 35, 12]) | ||
| // [20, 40, 70, 24] | ||
|
|
||
| ArrayFunctions.prototype.doubleArray = function(array){ | ||
| return array.map(function(number){ | ||
| return number * 2; | ||
| }); | ||
| }; | ||
| // ArrayFunctions.prototype.doubleArray = function(array){ | ||
| // return array.map(function(number){ | ||
| // return number * 2; | ||
| // }); | ||
| // }; | ||
|
|
||
| // 3) Define a function that takes an array with numbers and returns the result of multiplying each element by ten to the power of the position it's in: | ||
| // ArrayFunctions.superPower([1,2,3,4,5]) | ||
| // 54321 | ||
| // explanation: (1 x 10^0) + (2 x 10^1) + (3 x 10^2) + (4 x 10^3) + (5 x 10^4) | ||
| // explanation: (1) + (20) + (300) + (4000) + (50000) | ||
|
|
||
| ArrayFunctions.prototype.superPower = function(array){ | ||
| return array.reduce(function(sum, number, index){ | ||
| return sum + (number * (Math.pow(10, index))); | ||
| }); | ||
| } | ||
|
|
||
| module.exports = ArrayFunctions; | ||
| // ArrayFunctions.prototype.superPower = function(array){ | ||
| // return array.reduce(function(sum, number, index){ | ||
| // return sum + (number * (Math.pow(10, index))); | ||
| // }); | ||
| // } |
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
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,68 +1,133 @@ | ||
| var LetterSequence = function(){} | ||
| class LetterSequence { | ||
| constructor (){} | ||
|
|
||
| LetterSequence.prototype.createSequence = function(sequence){ | ||
| var characters = sequence.split(""); | ||
| var containerString = ""; | ||
| var repeatCount = 1; | ||
| createSequence (sequence) { | ||
| let characters = [...sequence]; | ||
| let containerString = ""; | ||
| let repeatCount = 1; | ||
|
|
||
| for (var i = 0; i < characters.length; i++){ | ||
| var currentChar = characters[i]; | ||
| var prevChar = characters[i - 1]; | ||
| var nextChar = characters[i + 1]; | ||
| for (let i = 0; i < characters.length; i++){ | ||
| let currentChar = characters[i]; | ||
| let prevChar = characters[i - 1]; | ||
| let nextChar = characters[i + 1]; | ||
|
|
||
| if (currentChar === prevChar){ | ||
| repeatCount++ | ||
| if (currentChar === prevChar){ | ||
| repeatCount++ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Semicolons |
||
| } | ||
| if (currentChar !== nextChar && repeatCount >= 1){ | ||
| let repeats = repeatCount > 1 ? String(repeatCount) : "" | ||
| containerString += (repeats + currentChar) | ||
| repeatCount = 1; | ||
| } | ||
| } | ||
| return containerString; | ||
| } | ||
|
|
||
| decodeSequence (sequence){ | ||
| let containerString = ""; | ||
| let characters = [...sequence]; | ||
|
|
||
| // If the sequence is broken, and the repeat count is greater than 1 | ||
| // add the letter and the repeat count to the return string | ||
| if (currentChar !== nextChar && repeatCount >= 1){ | ||
| var repeats = repeatCount > 1 ? String(repeatCount) : "" | ||
| containerString += (repeats + currentChar) | ||
| repeatCount = 1; | ||
| for (let i = 0; i < characters.length; i++){ | ||
| let current = characters[i]; | ||
| let nextChar = characters[i + 1]; | ||
|
|
||
| // If the current character is not a number, then there must be a letter after it | ||
| if (!isNaN(characters[i])){ | ||
| // So repeat it n times, and add it to our return value | ||
| let letters = this._repeat(current, nextChar); | ||
| containerString += letters; | ||
| // If the current character is a letter, and the last character is a letter, then | ||
| // it must be a lone letter | ||
| } else if (isNaN(characters[i]) && isNaN(characters[i - 1])){ | ||
| containerString += characters[i] | ||
| } | ||
| } | ||
| return containerString; | ||
| } | ||
|
|
||
| return containerString; | ||
| } | ||
| _repeat(count, character){ | ||
| let characters = ""; | ||
|
|
||
| LetterSequence.prototype.decodeSequence = function(sequence){ | ||
| var containerString = ""; | ||
| var characters = sequence.split(""); | ||
|
|
||
| for (var i = 0; i < characters.length; i++){ | ||
| var current = characters[i]; | ||
| var nextChar = characters[i + 1]; | ||
|
|
||
| // If the current character is not a number, then there must be a letter after it | ||
| if (!isNaN(characters[i])){ | ||
| // So repeat it n times, and add it to our return value | ||
| var letters = this._repeat(current, nextChar); | ||
| containerString += letters; | ||
| // If the current character is a letter, and the last character is a letter, then | ||
| // it must be a lone letter | ||
| } else if (isNaN(characters[i]) && isNaN(characters[i - 1])){ | ||
| containerString += characters[i] | ||
| if (count <= 1){ | ||
| count = 1 | ||
| } | ||
|
|
||
| for (let i = 0; i < count; i++){ | ||
| characters += character; | ||
| } | ||
| } | ||
|
|
||
| return containerString; | ||
| return characters; | ||
| } | ||
| } | ||
| module.exports = LetterSequence; | ||
|
|
||
| // Maybe there's a function to do this in ES6...? | ||
|
|
||
| LetterSequence.prototype._repeat = function(count, character){ | ||
| var characters = ""; | ||
|
|
||
| if (count <= 1){ | ||
| count = 1 | ||
| } | ||
| // let LetterSequence = function(){} | ||
|
|
||
| for (var i = 0; i < count; i++){ | ||
| characters += character; | ||
| } | ||
| // LetterSequence.prototype.createSequence = function(sequence){ | ||
| // let characters = sequence.split(""); | ||
| // let containerString = ""; | ||
| // let repeatCount = 1; | ||
| // | ||
| // for (let i = 0; i < characters.length; i++){ | ||
| // let currentChar = characters[i]; | ||
| // let prevChar = characters[i - 1]; | ||
| // let nextChar = characters[i + 1]; | ||
| // | ||
| // if (currentChar === prevChar){ | ||
| // repeatCount++ | ||
| // } | ||
| // | ||
| // // If the sequence is broken, and the repeat count is greater than 1 | ||
| // // add the letter and the repeat count to the return string | ||
| // if (currentChar !== nextChar && repeatCount >= 1){ | ||
| // let repeats = repeatCount > 1 ? String(repeatCount) : "" | ||
| // containerString += (repeats + currentChar) | ||
| // repeatCount = 1; | ||
| // } | ||
| // } | ||
| // | ||
| // return containerString; | ||
| // } | ||
| // | ||
| // LetterSequence.prototype.decodeSequence = function(sequence){ | ||
| // let containerString = ""; | ||
| // let characters = sequence.split(""); | ||
| // | ||
| // for (let i = 0; i < characters.length; i++){ | ||
| // let current = characters[i]; | ||
| // let nextChar = characters[i + 1]; | ||
| // | ||
| // // If the current character is not a number, then there must be a letter after it | ||
| // if (!isNaN(characters[i])){ | ||
| // // So repeat it n times, and add it to our return value | ||
| // let letters = this._repeat(current, nextChar); | ||
| // containerString += letters; | ||
| // // If the current character is a letter, and the last character is a letter, then | ||
| // // it must be a lone letter | ||
| // } else if (isNaN(characters[i]) && isNaN(characters[i - 1])){ | ||
| // containerString += characters[i] | ||
| // } | ||
| // } | ||
| // | ||
| // return containerString; | ||
| // } | ||
|
|
||
| return characters; | ||
| } | ||
| // Maybe there's a function to do this in ES6...? | ||
|
|
||
| module.exports = LetterSequence; | ||
| // LetterSequence.prototype._repeat = function(count, character){ | ||
| // let characters = ""; | ||
| // | ||
| // if (count <= 1){ | ||
| // count = 1 | ||
| // } | ||
| // | ||
| // for (let i = 0; i < count; i++){ | ||
| // characters += character; | ||
| // } | ||
| // | ||
| // return characters; | ||
| // } | ||
| // | ||
| // module.exports = LetterSequence; | ||
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.
const length
=>
const arrayLength
Give more detailed names to your variables :)