Skip to content

Solution - #1

Open
GILGIDIM wants to merge 6 commits into
masterfrom
solution
Open

Solution#1
GILGIDIM wants to merge 6 commits into
masterfrom
solution

Conversation

@GILGIDIM

@GILGIDIM GILGIDIM commented Jul 2, 2021

Copy link
Copy Markdown
Owner

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.

@GILGIDIM
GILGIDIM requested a review from ruimiguelcorreia July 2, 2021 09:23

@ruimiguelcorreia ruimiguelcorreia left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty good job here! Just some notes here and there but nothing major. Keep this repo as a library for the future :)

Comment thread src/arrays.js
const uppercaseWordsInArray = strings => {
// your code here
};
const uppercaseWordsInArray = strings => strings.map(toUpper => toUpper.toUpperCase());

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic is right, but as a suggestion, I would probably rename toUpper to string, which is more descriptive.

Comment thread src/arrays.js

const addToArray2 = (element, array) => {
// your code here
return [...array, element];

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can drop this return keyword, if you use the implicit return, as you did for the other functions.

Comment thread src/arrays.js
const reverseWordsInArray = strings => {
// your code here
};
const reverseWordsInArray = strings => strings.map(newString => newString.split("").reverse().join(""));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/arrays.js
// your code here
const newArray = [...array];
newArray.splice(index, 1);
return newArray;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logic works beautifully. Can you reduce the 3 lines to 1?

Comment thread src/arrays.js
const elementsStartingWithAVowel = strings => {
// your code here
};
const elementsStartingWithAVowel = strings => strings.filter((string) => (string.match(/^[aeiou]/i)));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The infamous regex 😂

Comment thread src/arrays.js

const sortByLastLetter = strings => {
// your code here
return strings.sort((a, b) => a.charCodeAt(a.length - 1) - b.charCodeAt(b.length - 1));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

Comment thread src/booleans.js
const truthiness = a => {
// your code here
};
const truthiness = a => !!a;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's also a cool method that you could use here.
Boolean(a)

Comment thread src/booleans.js
const containsVowels = string => {
// your code here
};
const containsVowels = string => Boolean(string.match(/[aeiou]/i));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, there it is.

Comment thread src/objects.js
const getProperty = (property, object) => {
// your code here
};
const getProperty = (property, object) => object[property];

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

Comment thread src/objects.js
if (person.age > 65) {
return true;
}
return false;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can have a cleaner version if you use the ternary operator!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants