diff --git a/src/arrays.js b/src/arrays.js index 822c49b7..e34f0da0 100644 --- a/src/arrays.js +++ b/src/arrays.js @@ -1,62 +1,141 @@ +//const array=["cat","dog","elephant","fox"]; const getNthElement = (index, array) => { + if (index>0 && index<=array.length-1){ + return array[index]; + } + if(index>array.length-1){ + return array[index-4]; + } + if(index===0){ + return array[0]; + } + }; + // your code here -}; + const arrayToCSVString = array => { - // your code here + + let n =[array]; + return n.toString(); }; + const csvStringToArray = string => { + return string.split(","); // your code here }; +//const array = []; +//const array2 = [1, 2, 3]; const addToArray = (element, array) => { + array.push(element); + + // your code here }; +const array = ['a', 'b', 'c']; +const array2 = [1, 2, 3]; const addToArray2 = (element, array) => { + let newArray=array.concat(element); + return newArray; // your code here }; const removeNthElement = (index, array) => { + return array.splice(index,1); // your code here }; const numbersToStrings = numbers => { + const m=numbers.toString(); + return m.split(','); // your code here }; const uppercaseWordsInArray = strings => { + const newString=strings.map((str) =>str.toUpperCase()) + return newString; // your code here }; const reverseWordsInArray = strings => { - // your code here -}; + return strings.map(string => string.split('').reverse().join('')); +} + + const onlyEven = numbers => { - // your code here -}; + let Array5=numbers.filter(number => number%2===0); + return Array5; -const removeNthElement2 = (index, array) => { - // your code here }; + +const removeNthElement2 = (index,array) => { + return array.filter((element)=>{ + if (element!==array[index]){ + return element + } + }) +} + + const elementsStartingWithAVowel = strings => { - // your code here -}; + return strings.filter((string)=>{ + if(string.charAt(0)==="a"||string.charAt(0)==="e"||string.charAt(0)==="i"||string.charAt(0)==="o"||string.charAt(0)==="u"||string.charAt(0)==="A"||string.charAt(0)==="E"||string.charAt(0)==="I"||string.charAt(0)==="O"||string.charAt(0)==="U"){ + return string + } + }) + + } + + + + + + const removeSpaces = string => { - // your code here + const stringArray=string.split(" "); + const namesCombined=stringArray.reduce((acc,curr)=>{ + return acc+curr + }) + return namesCombined; }; const sumNumbers = numbers => { - // your code here + const sumNumbers=numbers.reduce((acc,curr)=>{ + return acc+curr; + }) + return sumNumbers; }; const sortByLastLetter = strings => { - // your code here -}; + return strings.sort((a, b) => + (a.charCodeAt(a.length - 1) - b.charCodeAt(b.length - 1)) + )} + + + + //const stringy= strings.map((string)=>{ + //return string.split("").reverse().join("") + //}) + //const newS=stringy.sort(); + //return newS.split("").reverse().join("") + + + + +// + + + + + + + module.exports = { getNthElement, diff --git a/src/booleans.js b/src/booleans.js index 5ff6cb55..21f1d1ab 100644 --- a/src/booleans.js +++ b/src/booleans.js @@ -1,60 +1,141 @@ function negate(a) { + return !a; // your code here }; function both(a, b) { + if (a===true && b===true){ + return true; + }else{ + return false; + } // your code here -}; +} function either(a, b) { + if (a===true || b===true){ + return true + }else{ + return false; + } + }; // your code here -}; + function none(a, b) { + if (a===true || b===true){ + return false + }else{ + return true; + } // your code here }; function one(a, b) { - // your code here -}; + if(a===true && b===true){ + return false; + }else if (a===true || b===true){ + return true; + }else{ + return false; + } + }; + + function truthiness(a) { + return Boolean(a); + } + + // your code here -}; + function isEqual(a, b) { + if(a===b){ + return true; + }else{ + return false; + } // your code here }; function isGreaterThan(a, b) { + if(a>b){ + return true; + }else{ + return false; + } // your code here }; function isLessThanOrEqualTo(a, b) { + if (a<=b){ + return true; + }else{ + return false; + } // your code here }; function isOdd(a) { - // your code here + if(a%2!==0){ + return true; + }else{ + return false; + } + }; function isEven(a) { + if(a%2===0){ + return true; + }else{ + return false; + } + // your code here }; function isSquare(a) { + if (Number.isInteger(Math.sqrt(a))){ + return true; + }else{ + return false; + } // your code here }; function startsWith(char, string) { + if(string.startsWith(char)){ + return true; + }else { + return false; + } // your code here }; function containsVowels(string) { - // your code here -}; + + const vowels = ["a" ,"e" ,"i", "o","u","A","B","C","D","E"]; + let result=false; + for(let i=0;i { - // your code here -}; +const createPerson = (name, age) =>{ + + return {"name":name, + "age" : age,} + + } + + + const getName = object => { + return object.name + + }; + + const getProperty = (property, object) => { + const newojb = object + return newojb[property] + + }; + + const hasProperty = (property, object) => { + return property in object + + }; + + const isOver65 = person => { + + if(person.age>65){ + return true; + }else{ + return false; + } + } + + + const getAges = people => { + const newAges = people.map((person)=>{ + return person.age; + }) + return newAges + }; + + const findByName = (name, people) => { + return people.find((person)=>{ + return (person.name===name) + }) + + } + + + const findHondas = cars => { + return cars.filter((car)=>{ + if(car.manufacturer==="Honda"){ + return car; + } + + }) + + + }; + + const averageAge = people => { + let agesNew= people.map((person)=>{ + return person.age + }) + let newAge2= agesNew.reduce((acc,curr)=>{ + return acc+curr + },0) + return newAge2/(people.length) + } + + + + + + const createTalkingPerson = (name, age) => { + return { + name:name, + age:age, + introduce: function (newName) { + return `Hi ${newName}, my name is ${name} and I am ${age}!` + }, + } + + }; + + module.exports = { + createPerson, + getName, + getProperty, + hasProperty, + isOver65, + getAges, + findByName, + findHondas, + averageAge, + createTalkingPerson + }; + -const getName = object => { - // your code here -}; - -const getProperty = (property, object) => { - // your code here -}; - -const hasProperty = (property, object) => { - // your code here -}; - -const isOver65 = person => { - // your code here -}; - -const getAges = people => { - // your code here -}; - -const findByName = (name, people) => { - // your code here -}; - -const findHondas = cars => { - // your code here -}; - -const averageAge = people => { - // your code here -}; - -const createTalkingPerson = (name, age) => { - // your code here -}; - -module.exports = { - createPerson, - getName, - getProperty, - hasProperty, - isOver65, - getAges, - findByName, - findHondas, - averageAge, - createTalkingPerson -}; diff --git a/src/strings.js b/src/strings.js index ce02affa..a4a78537 100644 --- a/src/strings.js +++ b/src/strings.js @@ -1,24 +1,30 @@ function sayHello (string) { + return "Hello, " + string + "!"; // your code here }; function uppercase (string) { + return string.toUpperCase(); // your code here }; function lowercase (string) { + return string.toLowerCase(); // your code here }; function countCharacters (string) { + return string.length; // your code here }; function firstCharacter (string) { + return string.charAt(0); // your code here }; function firstCharacters (string, n) { + return string.substring(0,n); // your code here };