Conversation
ruimiguelcorreia
left a comment
There was a problem hiding this comment.
Pretty good job here! Just some notes here and there but nothing major. Keep this repo as a library for the future :)
| const uppercaseWordsInArray = strings => { | ||
| // your code here | ||
| }; | ||
| const uppercaseWordsInArray = strings => strings.map(toUpper => toUpper.toUpperCase()); |
There was a problem hiding this comment.
The logic is right, but as a suggestion, I would probably rename toUpper to string, which is more descriptive.
|
|
||
| const addToArray2 = (element, array) => { | ||
| // your code here | ||
| return [...array, element]; |
There was a problem hiding this comment.
You can drop this return keyword, if you use the implicit return, as you did for the other functions.
| const reverseWordsInArray = strings => { | ||
| // your code here | ||
| }; | ||
| const reverseWordsInArray = strings => strings.map(newString => newString.split("").reverse().join("")); |
There was a problem hiding this comment.
Same as before, string would be more descriptive, because technically you're iterating over existing strings, even if you return a reversed version of them.
| // your code here | ||
| const newArray = [...array]; | ||
| newArray.splice(index, 1); | ||
| return newArray; |
There was a problem hiding this comment.
Logic works beautifully. Can you reduce the 3 lines to 1?
| const elementsStartingWithAVowel = strings => { | ||
| // your code here | ||
| }; | ||
| const elementsStartingWithAVowel = strings => strings.filter((string) => (string.match(/^[aeiou]/i))); |
There was a problem hiding this comment.
The infamous regex 😂
|
|
||
| const sortByLastLetter = strings => { | ||
| // your code here | ||
| return strings.sort((a, b) => a.charCodeAt(a.length - 1) - b.charCodeAt(b.length - 1)); |
There was a problem hiding this comment.
Another way of solving this is reusing a function you've written - the one that reverses words. And then sort from there. But this also works!
| const truthiness = a => { | ||
| // your code here | ||
| }; | ||
| const truthiness = a => !!a; |
There was a problem hiding this comment.
There's also a cool method that you could use here.
Boolean(a)
| const containsVowels = string => { | ||
| // your code here | ||
| }; | ||
| const containsVowels = string => Boolean(string.match(/[aeiou]/i)); |
| const getProperty = (property, object) => { | ||
| // your code here | ||
| }; | ||
| const getProperty = (property, object) => object[property]; |
There was a problem hiding this comment.
Here's when it's useful to use square dotation over dot notation - when you're not sure about which property you're extracting from the object and you want to leave it as dynamic as possible! Keep this one in your notes!
| if (person.age > 65) { | ||
| return true; | ||
| } | ||
| return false; |
There was a problem hiding this comment.
You can have a cleaner version if you use the ternary operator!
Hi Rui, thanks for your help creating the PR!
I think this one should now be correct where I am requesting a PR to my own javascript-basics and comparing my solution branch to the forked master.