-
Notifications
You must be signed in to change notification settings - Fork 12
10 functions. Anastasiya Santalova #8
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
base: master
Are you sure you want to change the base?
10 functions. Anastasiya Santalova #8
Conversation
AnastasiyaSantalova/hw3.js
Outdated
|
|
||
| //add new separator between words | ||
| return arrOfLetters.reduce(function(acc, word) { | ||
| return acc + sp + word; |
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.
...at last merge all the words(Use separator space) and return it
It won't actually do that exactly.
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.
Actually, I don't understand, what do you mean
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.
Well, in the final string words containing your custom separator should be separated by whitespaces itself like (mind the gap) H.e.l.l.o w.o.r.l.d, but in your case it will be H.e.l.l.o.w.o.r.l.d since you use the same separator to divide words itself
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.
Exactly) Fixed!
AnastasiyaSantalova/hw3.js
Outdated
| }); | ||
|
|
||
| //add new separator between words | ||
| return arrOfLetters.join(sp); |
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.
As well as this one.
AnastasiyaSantalova/hw3.js
Outdated
|
|
||
| function stringExpansion(string) { | ||
|
|
||
| var repeatSimbol = 1; |
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.
Here and below typo in symbol
| // FUNCTION 2: convertation hash to array (via entries) | ||
|
|
||
| function convert (hash) { | ||
| return Object.entries(hash); |
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.
Object.entries is a part of ES6+
However I see that you have ES5 version below so it's just a tip for you to be aware of in case you will maintain legacy code
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.
Yes, I know, I recognized it when function was written and decided to save both variants
AnastasiyaSantalova/hw3.js
Outdated
|
|
||
| // check what kind of separator sring has | ||
|
|
||
| str.search('-')>0 ? sep = '-' : sep = '_'; |
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.
Please use whitespaces around arithmetic, comparison and assignment operators here and below
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.
Ok!
AnastasiyaSantalova/hw3.js
Outdated
|
|
||
| var arr = str.split(sep).map(function(word, ind) { | ||
|
|
||
| if (ind!=0) { |
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.
It's a good practice to always use === and !== operators to avoid implicit type coercion
AnastasiyaSantalova/hw3.js
Outdated
|
|
||
| var repeatSimbol = 1; | ||
|
|
||
| return string.split("").reduce(function(acc,simbol,ind,arr) { |
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.
Add whitespaces between function arguments
AnastasiyaSantalova/hw3.js
Outdated
|
|
||
| // FUNCTION 1: returns phrase with determined separator (via reduce) | ||
|
|
||
| function splitAndMerge (str, sp) { |
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.
Function's name usually is not separated from parentheses with whitespace
AnastasiyaSantalova/hw3.js
Outdated
|
|
||
| // check what kind of separator sring has | ||
|
|
||
| str.search('-')>0 ? sep = '-' : sep = '_'; |
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.
You can take a look at regular expressions, you could use them in split method describing all the symbols you want to match in one expression
AnastasiyaSantalova/hw3.js
Outdated
| countDown(2); | ||
|
|
||
|
|
||
| // FUNCTION 10: prototipe for bind() |
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.
PrototYpe :)
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.
Exactly!)
AnastasiyaSantalova/hw3.js
Outdated
|
|
||
| // if the symbol is number | ||
|
|
||
| if (isNaN(symbol)==false) { |
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.
Use triple equals operator + surround it by whitespaces
AnastasiyaSantalova/hw3.js
Outdated
| return b - a; | ||
| } | ||
|
|
||
| var numbers=[]; |
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.
Whitespaces
| return a - b; | ||
| } | ||
|
|
||
| var numbers=[]; |
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.
Whitespaces
AnastasiyaSantalova/hw3.js
Outdated
|
|
||
| function sum() { | ||
|
|
||
| var sumOfArgs=0; |
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.
Whitespaces
AnastasiyaSantalova/hw3.js
Outdated
| function sum1() { | ||
|
|
||
| var i = arguments.length - 1; | ||
| var newArguments=[]; |
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.
Whitespaces
AnastasiyaSantalova/hw3.js
Outdated
|
|
||
| return function () { | ||
|
|
||
| var innerArgs=[]; |
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.
Whitespaces
No description provided.