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

Mahoud solution #34

Open
wants to merge 1 commit 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
40 changes: 35 additions & 5 deletions src/arrays.js
Original file line number Diff line number Diff line change
@@ -1,61 +1,91 @@
const getNthElement = (index, array) => {
// your code here

let arrayIndex = index;
let arrayLenght = array.length;
if (arrayIndex < arrayLenght) {
return array[arrayIndex];
}
return Array[arrayLenght -(arrayIndex)];

};

const arrayToCSVString = array => {
// your code here
return array.join(",")

};

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

};

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

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

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

const numbersToStrings = numbers => {
// your code here

return numbers.toString().split(',')
};

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

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


};

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

const removeNthElement2 = (index, array) => {
// your code here
};
// your code here

};
const elementsStartingWithAVowel = strings => {
// your code here
const vowels = ['a','e','i','o','u'];
return vowels.map(function(vowel) {
return strings.find(function(string) {
return string.toLowerCase().charAt(0) === vowel;
});
});
};

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

const sumNumbers = numbers => {
// your code here
// your code here
return numbers.reduce((acc, curr) => acc + curr);
};

const sortByLastLetter = strings => {
// your code here

return strings.sort((a, b) => a.charCodeAt(a.length - 1) - b.charCodeAt(b.length - 1));
};

module.exports = {
Expand Down
52 changes: 48 additions & 4 deletions src/booleans.js
Original file line number Diff line number Diff line change
@@ -1,61 +1,100 @@
/* eslint-disable func-names */
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
if (a || b || a) {
return true;
}
return false;
};

const truthiness = a => {
// your code here
// your code her
if (a) {
return true;
}
return false;
};

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
if (a % 2 !== 0) {
return true;
}
return false;
};

const isEven = a => {
// your code here
if (a % 2 == 0) {
return true;
// eslint-disable-next-line no-else-return
} else {
return false;
}
};

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

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

const containsVowels = string => {
// your code here
const containsVowels = function(string) {
const vowels = ['a','e','i','o','u'];
// var stringLowercase = string.toLowerCase()
for(i = 0; i < vowels.length; i++){
if (vowels.includes(string.toLowerCase()[i])){
return true;
}
}
return false;
};

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

module.exports = {
Expand All @@ -75,3 +114,8 @@ module.exports = {
containsVowels,
isLowerCase
};

// program to count the number of vowels in a string

// defining vowels

53 changes: 32 additions & 21 deletions src/numbers.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,68 @@
const add = (a, b) => {
// your code here
return a + b;
};

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

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

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

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

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

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

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

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

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

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

module.exports = {
add,
subtract,
multiply,
divide,
power,
round,
roundUp,
roundDown,
absolute,
quotient,
remainder
add,
subtract,
multiply,
divide,
power,
round,
roundUp,
roundDown,
absolute,
quotient,
remainder
};
28 changes: 22 additions & 6 deletions src/objects.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,59 @@
const createPerson = (name, age) => {
// your code here
};

function createPerson(name, age) {
// your code here

return {
name: name,
age: 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 people.map((ages)=> ages.age)
};

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

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

const averageAge = people => {
// your code here
// eslint-disable-next-line func-names
return people.reduce((acc, curr) => acc + curr.age, 0) / people.length;
};

const createTalkingPerson = (name, age) => {
// your code here
};

module.exports = {
createPerson,
getName,
Expand Down
Loading