Skip to content
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
70 changes: 29 additions & 41 deletions src/arrays.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,50 @@
const getNthElement = (index, array) => {
// your code here
return array[index % array.length];
};

const arrayToCSVString = array => {
// your code here
};
const arrayToCSVString = array => array.toString();

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

const addToArray = (element, array) => {
// your code here
array.push(element);
};

const addToArray2 = (element, array) => {
// your code here
};
const addToArray2 = (element, array) => array.concat(element);

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

const numbersToStrings = numbers => {
// your code here
};
const numbersToStrings = numbers => numbers.map(String);

const uppercaseWordsInArray = strings => {
// your code here
};
const uppercaseWordsInArray = strings => strings.map(a => a.toUpperCase());

const reverseWordsInArray = strings => {
// your code here
};
const reverseWordsInArray = strings =>
strings.map(word => {
return word
.split("")
.reverse()
.join("");
});

const onlyEven = numbers => {
// your code here
};
const onlyEven = numbers => numbers.filter(number => number % 2 === 0);

const removeNthElement2 = (index, array) => {
// your code here
};
const removeNthElement2 = (index, array) =>
array.reduce((result, elem, i) => {
if (i !== index) result.push(elem);
return result;
}, []);

const elementsStartingWithAVowel = strings => {
// your code here
};
const elementsStartingWithAVowel = strings =>
strings.filter(str => /^[aeiouAEIOU]/i.test(str));

const removeSpaces = string => {
// your code here
};
const removeSpaces = string => string.replace(/\s/g, "");

const sumNumbers = numbers => {
// your code here
};
const sumNumbers = numbers => numbers.reduce((a, b) => a + b);

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

module.exports = {
getNthElement,
Expand Down
60 changes: 17 additions & 43 deletions src/booleans.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,36 @@
const negate = a => {
// your code here
};
const negate = a => !a;

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

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

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

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

const truthiness = a => {
// your code here
};
const truthiness = a => Boolean(a);

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

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

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

const isOdd = a => {
// your code here
};
const isOdd = a => !(a % 2 === 0);

const isEven = a => {
// your code here
};
const isEven = a => a % 2 === 0;

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

const startsWith = (char, string) => {
// your code here
};
const startsWith = (char, string) => string.startsWith(char);

const containsVowels = string => {
// your code here
};
const containsVowels = string => Boolean(string.match(/[aeiou]/gi));

const isLowerCase = string => {
// your code here
};
const isLowerCase = string => string === string.toLowerCase();

module.exports = {
negate,
Expand Down
44 changes: 11 additions & 33 deletions src/numbers.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,24 @@
const add = (a, b) => {
// your code here
};
const add = (a, b) => a + b;

const subtract = (a, b) => {
// your code here
};
const subtract = (a, b) => a - b;

const multiply = (a, b) => {
// your code here
};
const multiply = (a, b) => a * b;

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

const power = (a, b) => {
// your code here
};
const power = (a, b) => a ** b;

const round = a => {
// your code here
};
const round = a => Math.round(a);

const roundUp = a => {
// your code here
};
const roundUp = a => Math.ceil(a);

const roundDown = a => {
// your code here
};
const roundDown = a => Math.floor(a);

const absolute = a => {
// your code here
};
const absolute = a => Math.abs(a);

const quotient = (a, b) => {
// your code here
};
const quotient = (a, b) => Math.trunc(a / b);

const remainder = (a, b) => {
// your code here
};
const remainder = (a, b) => a % b;

module.exports = {
add,
Expand Down
46 changes: 22 additions & 24 deletions src/objects.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,39 @@
const createPerson = (name, age) => {
// your code here
return {
name,
age
};
};

const getName = object => {
// your code here
};
const getName = object => object.name;

const getProperty = (property, object) => {
// your code here
};
const getProperty = (property, object) => object[property];

const hasProperty = (property, object) => {
// your code here
};
const hasProperty = (property, object) => property in object;

const isOver65 = person => {
// your code here
};
const isOver65 = person => person.age > 65;

const getAges = people => {
// your code here
};
const getAges = people => people.map(person => person.age);

const findByName = (name, people) => {
// your code here
};
const findByName = (name, people) =>
people.filter(person => person.name === name)[0];

const findHondas = cars => {
// your code here
};
const findHondas = cars => cars.filter(car => car.manufacturer === "Honda");

const averageAge = people => {
// your code here
const ages = people.map(person => person.age);
const average = ages.reduce((a, b) => a + b);
return average / ages.length;
};

const createTalkingPerson = (name, age) => {
// your code here
const person = {
name,
age,
introduce: personname =>
`Hi ${personname}, my name is ${name} and I am ${age}!`
};
return person;
};

module.exports = {
Expand Down
24 changes: 6 additions & 18 deletions src/strings.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,14 @@
const sayHello = string => {
// your code here
};
const sayHello = string => `Hello, ${string}!`;

const uppercase = string => {
// your code here
};
const uppercase = string => string.toUpperCase();

const lowercase = string => {
// your code here
};
const lowercase = string => string.toLowerCase();

const countCharacters = string => {
// your code here
};
const countCharacters = string => string.length;

const firstCharacter = string => {
// your code here
};
const firstCharacter = string => string.charAt(0);

const firstCharacters = (string, n) => {
// your code here
};
const firstCharacters = (string, n) => string.substring(0, n);

module.exports = {
sayHello,
Expand Down
Loading