Skip to content

javascript-basics #27

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

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
43 changes: 23 additions & 20 deletions src/arrays.js
Original file line number Diff line number Diff line change
@@ -1,61 +1,64 @@
const getNthElement = (index, array) => {
// your code here
return array[index % array.length];
};

const arrayToCSVString = array => {
// your code here
return array[index .join];
};

const csvStringToArray = string => {
// your code here
return string[index .split(',')];
};

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

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

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

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

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

const reverseWordsInArray = strings => {
// your code here
return strings.maps(letters => letters.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
return array.filter((_, itemIndex) => itemIndex !== index);
};

const elementsStartingWithAVowel = strings => {
// your code here
const elementsStartingWithAVowel = (strings) => {
const vowels = ['a', 'e', 'i', 'o', 'u'];
return
};

const removeSpaces = string => {
// your code here
return [index.strip()];
};

const sumNumbers = numbers => {
// your code here
};
const sumNumbers = (numbers) => numbers.reduce((total, number) => {
return total + number
}, 0);

const sortByLastLetter = strings => {
// your code here
const sortByLastLetter = (strings) => {
const reverseString = (item) => item.split('').reverse().join('');
return strings.map(reverseString).sort().map(reverseString);
};

module.exports = {
Expand Down
30 changes: 15 additions & 15 deletions src/booleans.js
Original file line number Diff line number Diff line change
@@ -1,61 +1,61 @@
const negate = a => {
// your code here
return !a;
};

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
return !a && !b;
};

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

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

const isEqual = (a, b) => {
// your code here
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 (a % 2) === 1;
};

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

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

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

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

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

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

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

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

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

const power = (a, b) => {
// your code here
return Math.pow(a,b);
};

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

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

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

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

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

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

module.exports = {
Expand Down
31 changes: 20 additions & 11 deletions src/objects.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,50 @@
const createPerson = (name, age) => {
// your code here
name,
age,
createPerson, Function ()
return "name" + ' ,' + age
};

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

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

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

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

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

const findByName = (name, people) => {
// your code here
return people.find(object => object.name === name);
};

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

const averageAge = people => {
// your code here
const totalAge = people.reduce((prevAge, currentPerson) => {
return prevAge + currentPerson.age;
}, 0);
return totalAge / people.length;
};

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

module.exports = {
Expand Down
16 changes: 8 additions & 8 deletions src/strings.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
const sayHello = string => {
// your code here
const sayHello = (string) => {
return ("Hello, " + string + "!");
};

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

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

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

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

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

module.exports = {
Expand Down
Loading