Skip to content
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

code review #26

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 112 additions & 17 deletions src/arrays.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,157 @@
const getNthElement = (index, array) => {
// your code here
//pass
/*We need a more dynamic way including modulus
because using -4 is not dynamic meaning we would
have to keep making new code for any updates!!!
.length is what we need to use but I have tried
and not figured out the correct method yet! */
while (index >3) {index = index -4};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is smart, you just need to use the array.length in your while condition

while (index >array.length)

return array[index];
/*but this works for now*/

};

const arrayToCSVString = array => {
// your code here
//pass
return array.toString('')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

should have used .join here

};

const csvStringToArray = string => {
// your code here
//pass
return string.split(",")
};

const addToArray = (element, array) => {
// your code here
// pass
array.push(element);
//array.push([element]);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

you should get rid of commented out code, commented code is dead code! 💀

//array.concat(element);
//array.concat([element]);
//array.push(4)
//array.concat(4)
};

const addToArray2 = (element, array) => {
// your code here

return array.concat(element);
//array.push(element);
//return array
};

const removeNthElement = (index, array) => {
// your code here
return array.splice(index,1);

};

const numbersToStrings = numbers => {
// your code here
//pass
/*numbers.toString converts the entire array to a string, .split(",")
let me change each individual number to a string */
return numbers.toString().split(",")
};

const uppercaseWordsInArray = strings => {
// your code here
//pass
/* strings.map lets me select all the strings in the array and create a new array,
the array method .map to .toUpperCase changes the array to uppercase*/
return strings.map((strings => strings.toUpperCase()))
};

const reverseWordsInArray = strings => {
// your code here
//pass
/*return strings.reverse = reverses the order of the array
The split() method splits a String object into an array of string
by separating the string into sub strings.
The reverse() method reverses an array in place. The first array
element becomes the last and the last becomes the first.
The join() method joins all elements of an array into a string.
last I added .map, .map selects each individual element in array
(I struggled to figure how to select the individual elements .map was the one)*/
return strings.map(strings => strings.split("").reverse().join(""));
};

const onlyEven = numbers => {
// your code here
//pass
/*filter function maybe???
using filter and then giving a function named that function X.
X % 2 should give back all even numbers but I don't quite understand the maths per usual
Copy link
Contributor Author

Choose a reason for hiding this comment

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

maths is simple here

% 2 is saying

divide the number by 2, if the remainder is zero, then you have an even number :)

https://stackoverflow.com/questions/51876350/javascript-filtering-even-numbers
*/
let num = numbers.filter(function(x){
return x % 2 === 0;
})
return num
};

const removeNthElement2 = (index, array) => {
// your code here
//need to check
/* let set1 = "";
set1 = array.splice(0, 2);
return array;*/
//let set1 = "";
//set1 = array.slice(1, 2)
let arrayCopy = [...array];
arrayCopy.splice(index,1);
return arrayCopy;


};

const elementsStartingWithAVowel = strings => {
// your code here
//Need to select the case sensitive elements
/*filter function and regEx */
/* Array.prototype.filter() returns a new array with all the
elements that pass (return a truthy value) the predicate.
RegExp.prototype.test() returns true if the RegExp finds a match on the string you pass in.
- Then, /^[aeiou]/i means:
- ^ matches the start of the string.
- [aeiou] matches any of the characters inside the square brackets, a single time.
- i is a case-insensitive modifier*/
//https://stackoverflow.com/questions/52028403/filter-array-of-strings-keeping-only-ones-starting-with-vowels
//this part has passed!
return strings.filter(strings => /^[aeiou]/i.test(strings));

};

const removeSpaces = string => {
// your code here


//string.replace(/ /g, "")
// let string = str
//str.replace(/\s+/g, '');
//string.splice(" ").join("");
// used reg ex, \s white space, /g global
return string.replace(/\s/g, "")
// return string


};

const sumNumbers = numbers => {
// your code here
};
/*let total = 0
for (i = 0; i < numbers.length; ++i) {
total + numbers[i];}
return total*/
const reducer = (accumulator, currentValue) => accumulator + currentValue;
return numbers.reduce(reducer);


};

const sortByLastLetter = strings => {
// your code here
};
//strings.sort(function(a, b){return a-b});
/* strings.sort(function(a, b) {
strings.reverse;
return b - a
});*/
//return a.replace(/^\W+/, 'z').localeCompare(b.replace(/^\W+/, 'z'));
//strings.sort(function(a, b){return b-a})

const reversedWords = reverseWordsInArray(strings).sort();
return reverseWordsInArray(reversedWords);

};


module.exports = {
getNthElement,
Expand Down
71 changes: 53 additions & 18 deletions src/booleans.js
Original file line number Diff line number Diff line change
@@ -1,61 +1,96 @@
const negate = a => {
// your code here
if (a && a){
Copy link
Contributor Author

Choose a reason for hiding this comment

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

return !a would have sufficed here

return false
}
else
return true

};

const both = (a, b) => {
// your code here
return a && b;
};

const either = (a, b) => {
// your code here
return a || b;

};

const none = (a, b) => {
// your code here
if (a === false && b === false){
return true
}
else
return false

};

const one = (a, b) => {
// your code here
if (a === true && b === false){
return true
}
else if (a !== true && b === true){
return true
}
else
return false
};

const truthiness = a => {
// your code here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

return Boolean(a) would have sufficed

if(a) {
return true;
}
else {
return false }

};

const isEqual = (a, b) => {
// your code here
const isEqual = (a, b) => {
return a === b

};

const isGreaterThan = (a, b) => {
// your code here
return a > b
};

const isLessThanOrEqualTo = (a, b) => {
// your code here
return a <= b
};

const isOdd = a => {
// your code here
return Math.abs(a % 2) == 1;

};

const isEven = a => {
// your code here
return Math.abs(a % 2) == 0;
};

const isSquare = a => {
// your code here
return Math.sqrt(a) % 1 === 0;

};

const startsWith = (char, string) => {
// your code here
};
return (char, string.startsWith("a", "aardvark"))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

return string.startsWith(char)

};

const containsVowels = string => {
if (string.match(/([aeiouAEIOU])\w+/g)) {
return true;
} else {
return false;
}

const containsVowels = string => {
// your code here
};

const isLowerCase = string => {
// your code here
if (string === string.toLowerCase()){
return true;
}
else return false
};

module.exports = {
Expand Down
Loading