From a844e572c5e31e30655800ebb566104295eead6d Mon Sep 17 00:00:00 2001 From: DevWilfredo Date: Mon, 31 Mar 2025 17:10:57 +0000 Subject: [PATCH 1/2] First commit --- exercises/001-isOldEnoughToDrink/app.js | 2 + exercises/002-isOldEnoughToDrive/app.js | 2 + exercises/003-isOldEnoughToVote/app.js | 2 + .../004-isOldEnoughToDrinkAndDrive/app.js | 2 +- exercises/005-checkAge/app.js | 4 +- exercises/006-getFullName/app.js | 1 + exercises/007-getLengthOfWord/app.js | 1 + exercises/008-getLengthOfTwoWords/app.js | 1 + exercises/009-getLengthOfThreeWords/app.js | 1 + exercises/010-isSameLength/app.js | 6 ++- exercises/011-isGreaterThanTen/app.js | 2 + exercises/012-isLessThanThirty/app.js | 3 +- exercises/013-equalsTen/app.js | 4 +- exercises/014-isLessThan/app.js | 2 + exercises/015-isGreaterThan/app.js | 3 +- exercises/016-isEqualTo/app.js | 6 ++- exercises/017-isEven/app.js | 9 +++- exercises/018-isOdd/app.js | 9 +++- exercises/019-areBothOdd/app.js | 7 +++ exercises/020-isEitherEven/app.js | 9 +++- exercises/021-isOddLength/app.js | 3 ++ exercises/022-isEvenLength/app.js | 5 ++- .../023-computeAverageLengthOfWords/app.js | 5 ++- exercises/024-isEvenAndGreaterThanTen/app.js | 5 ++- exercises/025-average/app.js | 5 ++- exercises/026-computeAreaOfATriangle/app.js | 3 ++ exercises/027-cube/app.js | 5 ++- exercises/028-square/app.js | 3 ++ exercises/029-getProperty/app.js | 2 +- exercises/030-addProperty/app.js | 3 +- exercises/031-removeProperty/app.js | 3 +- exercises/032-addFullNameProperty/app.js | 16 +++++-- exercises/033-addObjectProperty/app.js | 3 +- exercises/034-isPersonOldEnoughToDrive/app.js | 2 +- exercises/035-isPersonOldEnoughToVote/app.js | 2 +- exercises/036-isPersonOldEnoughToDrink/app.js | 2 +- exercises/037-addArrayProperty/app.js | 10 ++++- exercises/038-computeAreaOfARectangle/app.js | 2 +- .../039-computePerimeterOfARectangle/app.js | 1 + .../040-computePerimeterOfATriangle/app.js | 1 + .../041-computeTripledAreaOfARectangle/app.js | 1 + .../042-computePerimeterOfACircle/app.js | 1 + exercises/043-computeAreaOfACircle/app.js | 1 + exercises/044-computePower/app.js | 1 + exercises/045-computeSquareRoot/app.js | 1 + exercises/046-doubleSquareRootOf/app.js | 2 +- exercises/047-isEitherEvenOrAreBoth7/app.js | 2 +- exercises/048-isEitherEvenAndLessThan9/app.js | 1 + exercises/049-computeAverageOfNumbers/app.js | 11 +++++ exercises/050-getNthElement/app.js | 2 +- exercises/051-getFirstElement/app.js | 1 + exercises/052-getLastElement/app.js | 2 +- exercises/053-addToFront/app.js | 2 + exercises/054-addToBack/app.js | 2 + exercises/055-joinArrays/app.js | 1 + exercises/056-getElementsAfter/app.js | 1 + exercises/057-getElementsUpTo/app.js | 4 +- exercises/058-removeFromFront/app.js | 2 + exercises/059-removeFromBack/app.js | 2 + exercises/060-removeFromFrontOfNew/app.js | 1 + exercises/061-removeFromBackOfNew/app.js | 1 + exercises/062-countCharacter/app.js | 6 ++- exercises/063-getAllLetters/app.js | 5 +++ exercises/064-getAllWords/app.js | 1 + exercises/065-or/app.js | 7 +++ exercises/066-extend/app.js | 22 ++++++---- exercises/067-removeNumbersLargerThan/app.js | 18 +++++--- exercises/068-removeNumbersLessThan/app.js | 5 +++ .../069-removeStringValuesLongerThan/app.js | 9 +++- exercises/070-removeEvenValues/app.js | 9 +++- exercises/071-countNumberOfKeys/app.js | 5 +++ exercises/072-removeOddValues/app.js | 5 +++ exercises/073-removeArrayValues/app.js | 17 ++++++- exercises/074-removeNumberValues/app.js | 6 ++- exercises/075-removeStringValues/app.js | 6 ++- .../076-convertDoubleSpaceToSingle/app.js | 1 + exercises/077-areValidCredentials/app.js | 3 ++ exercises/078-getIndexOf/app.js | 9 ++++ .../079-findMinLengthOfThreeWords/app.js | 5 ++- .../080-findMaxLengthOfThreeWords/app.js | 5 ++- exercises/081-repeatString/app.js | 2 +- exercises/082-getLongestOfThreeWords/app.js | 5 +++ exercises/083-findShortestOfThreeWords/app.js | 4 ++ exercises/084-joinThreeArrays/app.js | 2 + exercises/085-addToFrontOfNew/app.js | 2 + exercises/086-addToBackOfNew/app.js | 2 + exercises/087-getAllElementsButNth/app.js | 2 + .../087-getAllElementsButNth/solution.hide.js | 12 ++++- exercises/088-keep/app.js | 6 +++ exercises/089-removeElement/app.js | 4 ++ exercises/090-filterOddLengthWords/app.js | 1 + exercises/091-filterEvenLengthWords/app.js | 1 + .../092-getFirstElementOfProperty/app.js | 15 +++++++ exercises/093-getNthElementOfProperty/app.js | 13 ++++++ exercises/094-getLastElementOfProperty/app.js | 13 ++++++ .../app.js | 15 +++++++ .../app.js | 16 ++++++- .../app.js | 16 ++++++- .../098-getOddLengthWordsAtProperty/app.js | 15 +++++++ .../099-getAverageOfElementsAtProperty/app.js | 10 +++++ .../100-getEvenLengthWordsAtProperty/app.js | 10 +++++ exercises/101-getOddElementsAtProperty/app.js | 4 ++ .../102-getEvenElementsAtProperty/app.js | 4 ++ .../103-getSquaredElementsAtProperty/app.js | 4 ++ .../104-getSmallestElementAtProperty/app.js | 5 +++ .../105-getLargestElementAtProperty/app.js | 4 ++ .../106-getAllButLastElementOfProperty/app.js | 5 +++ .../107-getElementOfArrayProperty/app.js | 4 ++ .../app.js | 4 ++ exercises/109-Select/app.js | 19 ++++++++ .../110-getSumOfAllElementsAtProperty/app.js | 6 ++- exercises/111-countAllCharacters/app.js | 14 ++++++ .../112-getLengthOfLongestElement/app.js | 10 +++++ exercises/113-squareElements/app.js | 3 +- exercises/114-filterOddElements/app.js | 3 +- .../115-computeProductOfAllElements/app.js | 5 +++ exercises/116-filterEvenElements/app.js | 1 + .../117-getLengthOfShortestElement/app.js | 10 +++++ exercises/118-getLongestElement/app.js | 16 +++++-- exercises/119-findSmallestElement/app.js | 6 ++- exercises/120-findShortestElement/app.js | 13 +++++- exercises/121-getLargestElement/app.js | 5 +++ exercises/122-computeSumOfAllElements/app.js | 1 + exercises/123-joinArraysOfArrays/app.js | 13 +++++- .../app.js | 21 ++++++--- .../app.js | 14 +++++- .../126-getLongestWordOfMixedElements/app.js | 12 ++++- .../app.js | 23 +++++++--- exercises/128-averageIntegers/app.js | 2 + exercises/129-calculateBillTotal/app.js | 2 + exercises/130-multiplyBetween/app.js | 9 ++++ exercises/131-computeSumBetween/app.js | 9 ++++ exercises/132-computeSummationToN/app.js | 6 ++- exercises/133-convertScoreToGrade/app.js | 17 ++++++- .../134-convertScoreToGradeWithPlus/app.js | 29 ++++++++++-- exercises/135-computeFactorialOfN/app.js | 7 ++- exercises/136-sumDigits/app.js | 23 +++++++--- exercises/137-computeCompoundInterest/app.js | 3 +- exercises/138-modulo/app.js | 8 ++++ exercises/139-multiply/app.js | 15 ++++++- exercises/140-isOddWithoutModulo/app.js | 4 +- exercises/141-isEvenWithoutModulo/app.js | 1 + exercises/142.1-ArrayToObject/app.js | 4 ++ exercises/142.2-ArrayToObject/app.js | 7 ++- exercises/142.3-ArrayToObject/app.js | 9 ++++ exercises/143.1-ObjectToArray/app.js | 1 + exercises/143.2-ObjectToArray/app.js | 1 + exercises/143.3-ObjectToArray/app.js | 5 +++ exercises/144-getStringLength/app.js | 5 +++ exercises/145-GreetCustomers/app.js | 12 ++++- exercises/146-flipPairs/app.js | 1 + exercises/147-flipEveryNChars/app.js | 20 ++++++--- exercises/148-detectOutlierValue/app.js | 32 ++++++++++---- exercises/149-findPairForSum/app.js | 7 +++ exercises/150-isRotated/app.js | 33 +++++++++++--- exercises/151-search/app.js | 14 +++++- exercises/152-isogram/app.js | 16 +++++-- exercises/153-phoneNumber/app.js | 8 ++-- exercises/154-longestPalindrome/app.js | 16 +++++-- exercises/155.1-FashionInventory-A/app.js | 16 ++++--- exercises/155.2-FashionInventory-B/app.js | 11 +++++ exercises/155.3-FashionInventory-C/app.js | 44 +++++++++++-------- exercises/155.4-FashionInventory-D/app.js | 16 ++++++- 163 files changed, 990 insertions(+), 161 deletions(-) diff --git a/exercises/001-isOldEnoughToDrink/app.js b/exercises/001-isOldEnoughToDrink/app.js index c4d3bab4d..66406c8de 100644 --- a/exercises/001-isOldEnoughToDrink/app.js +++ b/exercises/001-isOldEnoughToDrink/app.js @@ -1,4 +1,6 @@ function isOldEnoughToDrink(age) { // your code here + let result = age>= 21 ? true :false; + return result } diff --git a/exercises/002-isOldEnoughToDrive/app.js b/exercises/002-isOldEnoughToDrive/app.js index 0ab7348dd..9b341ca8d 100644 --- a/exercises/002-isOldEnoughToDrive/app.js +++ b/exercises/002-isOldEnoughToDrive/app.js @@ -1,4 +1,6 @@ function isOldEnoughToDrive(age) { // your code here + let result = age>= 16 ? true :false; + return result } diff --git a/exercises/003-isOldEnoughToVote/app.js b/exercises/003-isOldEnoughToVote/app.js index 63c4efb41..9f3d2b77a 100644 --- a/exercises/003-isOldEnoughToVote/app.js +++ b/exercises/003-isOldEnoughToVote/app.js @@ -1,4 +1,6 @@ function isOldEnoughToVote(age) { // your code here + let result = age>= 18 ? true :false; + return result } diff --git a/exercises/004-isOldEnoughToDrinkAndDrive/app.js b/exercises/004-isOldEnoughToDrinkAndDrive/app.js index c8c52473a..ae49a9e7c 100644 --- a/exercises/004-isOldEnoughToDrinkAndDrive/app.js +++ b/exercises/004-isOldEnoughToDrinkAndDrive/app.js @@ -1,4 +1,4 @@ function isOldEnoughToDrinkAndDrive(age) { // your code here - + return false } diff --git a/exercises/005-checkAge/app.js b/exercises/005-checkAge/app.js index 0ff57081e..984592b1f 100644 --- a/exercises/005-checkAge/app.js +++ b/exercises/005-checkAge/app.js @@ -1,4 +1,6 @@ function checkAge(name, age) { // your code here - + let message = age < 21 ? `Go home, ${name}!` : `Welcome, ${name}!`; + return message; + } diff --git a/exercises/006-getFullName/app.js b/exercises/006-getFullName/app.js index e8d8b83a8..a00357c07 100644 --- a/exercises/006-getFullName/app.js +++ b/exercises/006-getFullName/app.js @@ -1,4 +1,5 @@ function getFullName(firstName, lastName) { // your code here + return `${firstName} ${lastName}`; } diff --git a/exercises/007-getLengthOfWord/app.js b/exercises/007-getLengthOfWord/app.js index 8d04d4f58..02f38ffed 100644 --- a/exercises/007-getLengthOfWord/app.js +++ b/exercises/007-getLengthOfWord/app.js @@ -1,4 +1,5 @@ function getLengthOfWord(word) { // your code here + return word.length; } diff --git a/exercises/008-getLengthOfTwoWords/app.js b/exercises/008-getLengthOfTwoWords/app.js index 032c8cff4..7c23ea45b 100644 --- a/exercises/008-getLengthOfTwoWords/app.js +++ b/exercises/008-getLengthOfTwoWords/app.js @@ -1,4 +1,5 @@ function getLengthOfTwoWords(word1, word2) { // your code here + return word1.length + word2.length; } diff --git a/exercises/009-getLengthOfThreeWords/app.js b/exercises/009-getLengthOfThreeWords/app.js index 9049a6d5d..6ed192219 100644 --- a/exercises/009-getLengthOfThreeWords/app.js +++ b/exercises/009-getLengthOfThreeWords/app.js @@ -1,5 +1,6 @@ function getLengthOfThreeWords(word1, word2, word3) { // your code here + return word1.length + word2.length + word3.length; } diff --git a/exercises/010-isSameLength/app.js b/exercises/010-isSameLength/app.js index 6ebc804ae..23cd4030e 100644 --- a/exercises/010-isSameLength/app.js +++ b/exercises/010-isSameLength/app.js @@ -1 +1,5 @@ -// Write your function here \ No newline at end of file +// Write your function here +function isSameLength(word1,word2){ + let result = word1.length == word2.length ? true : false; + return result; +} \ No newline at end of file diff --git a/exercises/011-isGreaterThanTen/app.js b/exercises/011-isGreaterThanTen/app.js index b60c49b11..638187997 100644 --- a/exercises/011-isGreaterThanTen/app.js +++ b/exercises/011-isGreaterThanTen/app.js @@ -1,4 +1,6 @@ function isGreaterThanTen(num) { // your code here + let result = num>10 ? true : false; + return result; } diff --git a/exercises/012-isLessThanThirty/app.js b/exercises/012-isLessThanThirty/app.js index a9612b873..426bb4592 100644 --- a/exercises/012-isLessThanThirty/app.js +++ b/exercises/012-isLessThanThirty/app.js @@ -1,4 +1,5 @@ function isLessThan30(num) { // your code here - + let result = num<30 ? true : false; + return result; } diff --git a/exercises/013-equalsTen/app.js b/exercises/013-equalsTen/app.js index 0d5c28e62..3f76581eb 100644 --- a/exercises/013-equalsTen/app.js +++ b/exercises/013-equalsTen/app.js @@ -1,4 +1,6 @@ function equalsTen(num) { // your code here - + + let result = num==10 ? true : false; + return result; } diff --git a/exercises/014-isLessThan/app.js b/exercises/014-isLessThan/app.js index d7572d4ad..765a8bee8 100644 --- a/exercises/014-isLessThan/app.js +++ b/exercises/014-isLessThan/app.js @@ -1,3 +1,5 @@ function isLessThan(num1, num2) { // your code here + let result = num2num1? true : false; + return result; } diff --git a/exercises/016-isEqualTo/app.js b/exercises/016-isEqualTo/app.js index 6ebc804ae..a2282fa0d 100644 --- a/exercises/016-isEqualTo/app.js +++ b/exercises/016-isEqualTo/app.js @@ -1 +1,5 @@ -// Write your function here \ No newline at end of file +// Write your function here +function isEqualTo(num1, num2) { + let result = num2 === num1 ? true : false; + return result; +} \ No newline at end of file diff --git a/exercises/017-isEven/app.js b/exercises/017-isEven/app.js index 6ebc804ae..514974feb 100644 --- a/exercises/017-isEven/app.js +++ b/exercises/017-isEven/app.js @@ -1 +1,8 @@ -// Write your function here \ No newline at end of file +// Write your function here +function isEven(num){ + if(num%2==0){ + return true; + }else{ + return false; + } +} \ No newline at end of file diff --git a/exercises/018-isOdd/app.js b/exercises/018-isOdd/app.js index 6ebc804ae..af8da558e 100644 --- a/exercises/018-isOdd/app.js +++ b/exercises/018-isOdd/app.js @@ -1 +1,8 @@ -// Write your function here \ No newline at end of file +// Write your function here +function isOdd(num){ + if(num%3==0){ + return true; + }else{ + return false; + } +} \ No newline at end of file diff --git a/exercises/019-areBothOdd/app.js b/exercises/019-areBothOdd/app.js index 3e2df3368..827c726e7 100644 --- a/exercises/019-areBothOdd/app.js +++ b/exercises/019-areBothOdd/app.js @@ -1 +1,8 @@ // Write your function here +function areBothOdd(num1, num2){ + if(num1%2!=0 && num2%2!=0){ + return true; + }else{ + return false; + } +} \ No newline at end of file diff --git a/exercises/020-isEitherEven/app.js b/exercises/020-isEitherEven/app.js index 6ebc804ae..66d3b14ab 100644 --- a/exercises/020-isEitherEven/app.js +++ b/exercises/020-isEitherEven/app.js @@ -1 +1,8 @@ -// Write your function here \ No newline at end of file +// Write your function here +function isEitherEven(num1, num2){ + if(num1%2==0 || num2%2==0){ + return true; + }else{ + return false; + } +} \ No newline at end of file diff --git a/exercises/021-isOddLength/app.js b/exercises/021-isOddLength/app.js index 3e2df3368..0c0921125 100644 --- a/exercises/021-isOddLength/app.js +++ b/exercises/021-isOddLength/app.js @@ -1 +1,4 @@ // Write your function here +const isOddLength = (str)=>{ + return str.length%2!=0 ? true : false; +} diff --git a/exercises/022-isEvenLength/app.js b/exercises/022-isEvenLength/app.js index 6ebc804ae..acf59ad20 100644 --- a/exercises/022-isEvenLength/app.js +++ b/exercises/022-isEvenLength/app.js @@ -1 +1,4 @@ -// Write your function here \ No newline at end of file +// Write your function here +const isEvenLength = (str)=>{ + return str.length%2==0 ? true : false; +} diff --git a/exercises/023-computeAverageLengthOfWords/app.js b/exercises/023-computeAverageLengthOfWords/app.js index 6ebc804ae..47870f015 100644 --- a/exercises/023-computeAverageLengthOfWords/app.js +++ b/exercises/023-computeAverageLengthOfWords/app.js @@ -1 +1,4 @@ -// Write your function here \ No newline at end of file +// Write your function here +const computeAverageLengthOfWords = (str1, str2)=>{ + return (str1.length+str2.length)/2; +} \ No newline at end of file diff --git a/exercises/024-isEvenAndGreaterThanTen/app.js b/exercises/024-isEvenAndGreaterThanTen/app.js index 6ebc804ae..561966733 100644 --- a/exercises/024-isEvenAndGreaterThanTen/app.js +++ b/exercises/024-isEvenAndGreaterThanTen/app.js @@ -1 +1,4 @@ -// Write your function here \ No newline at end of file +// Write your function here +function isEvenAndGreaterThanTen(num){ + return (num%2==0 && num>10) ? true : false +} \ No newline at end of file diff --git a/exercises/025-average/app.js b/exercises/025-average/app.js index 6ebc804ae..82cc6cfab 100644 --- a/exercises/025-average/app.js +++ b/exercises/025-average/app.js @@ -1 +1,4 @@ -// Write your function here \ No newline at end of file +// Write your function here +const average = (num1, num2)=>{ + return(num1+num2)/2; +} \ No newline at end of file diff --git a/exercises/026-computeAreaOfATriangle/app.js b/exercises/026-computeAreaOfATriangle/app.js index 3e2df3368..54b802359 100644 --- a/exercises/026-computeAreaOfATriangle/app.js +++ b/exercises/026-computeAreaOfATriangle/app.js @@ -1 +1,4 @@ // Write your function here +const computeAreaOfATriangle= (b,h)=>{ + return (b*h)/2; +} \ No newline at end of file diff --git a/exercises/027-cube/app.js b/exercises/027-cube/app.js index 6ebc804ae..ddc18ccf4 100644 --- a/exercises/027-cube/app.js +++ b/exercises/027-cube/app.js @@ -1 +1,4 @@ -// Write your function here \ No newline at end of file +// Write your function here +function cube(num){ + return num**3; +} \ No newline at end of file diff --git a/exercises/028-square/app.js b/exercises/028-square/app.js index 3e2df3368..4f12975ca 100644 --- a/exercises/028-square/app.js +++ b/exercises/028-square/app.js @@ -1 +1,4 @@ // Write your function here +const square = (num)=>{ + return num**2; +} diff --git a/exercises/029-getProperty/app.js b/exercises/029-getProperty/app.js index c83e6b544..86e703b90 100644 --- a/exercises/029-getProperty/app.js +++ b/exercises/029-getProperty/app.js @@ -1,4 +1,4 @@ function getProperty(obj, key) { // your code here - + return obj[key]; } diff --git a/exercises/030-addProperty/app.js b/exercises/030-addProperty/app.js index e6c3fa031..43c65a9df 100644 --- a/exercises/030-addProperty/app.js +++ b/exercises/030-addProperty/app.js @@ -1,4 +1,5 @@ function addProperty(obj, key) { // your code here - + obj[key] = true; + return obj; } diff --git a/exercises/031-removeProperty/app.js b/exercises/031-removeProperty/app.js index 56edcf7c5..0fa13f5b6 100644 --- a/exercises/031-removeProperty/app.js +++ b/exercises/031-removeProperty/app.js @@ -1,4 +1,5 @@ function removeProperty(obj, key) { // your code here - + delete obj[key]; + return obj; } diff --git a/exercises/032-addFullNameProperty/app.js b/exercises/032-addFullNameProperty/app.js index db6651bc1..648f4829e 100644 --- a/exercises/032-addFullNameProperty/app.js +++ b/exercises/032-addFullNameProperty/app.js @@ -1,4 +1,12 @@ -function addFullNameProperty(obj) { - // Add your code after this line - -} \ No newline at end of file +function addFullNameProperty(obj){ + let newObj = obj; + newObj['fullName'] = newObj['firstName'] + " " + newObj['lastName']; + return newObj; +} + +let person = { + firstName: 'Jade', + lastName: 'Smith' +}; +addFullNameProperty(person); +console.log(person.fullName); \ No newline at end of file diff --git a/exercises/033-addObjectProperty/app.js b/exercises/033-addObjectProperty/app.js index 7f59b8c20..4c952ccb2 100644 --- a/exercises/033-addObjectProperty/app.js +++ b/exercises/033-addObjectProperty/app.js @@ -1,4 +1,5 @@ function addObjectProperty(obj1, key, obj2) { // Add your code after this line - + obj1[key] = obj2; + return obj1; } \ No newline at end of file diff --git a/exercises/034-isPersonOldEnoughToDrive/app.js b/exercises/034-isPersonOldEnoughToDrive/app.js index a319c0d29..92efc140d 100644 --- a/exercises/034-isPersonOldEnoughToDrive/app.js +++ b/exercises/034-isPersonOldEnoughToDrive/app.js @@ -1,4 +1,4 @@ function isPersonOldEnoughToDrive(person) { // Add your code after this line - + return person.age >= 16 ? true : false; } \ No newline at end of file diff --git a/exercises/035-isPersonOldEnoughToVote/app.js b/exercises/035-isPersonOldEnoughToVote/app.js index 4f1c12a60..8cda7aa1f 100644 --- a/exercises/035-isPersonOldEnoughToVote/app.js +++ b/exercises/035-isPersonOldEnoughToVote/app.js @@ -1,4 +1,4 @@ function isPersonOldEnoughToVote(person) { // Add your code after this line - + return person.age >= 18 ? true : false; } \ No newline at end of file diff --git a/exercises/036-isPersonOldEnoughToDrink/app.js b/exercises/036-isPersonOldEnoughToDrink/app.js index 09259549b..158223058 100644 --- a/exercises/036-isPersonOldEnoughToDrink/app.js +++ b/exercises/036-isPersonOldEnoughToDrink/app.js @@ -1,4 +1,4 @@ function isPersonOldEnoughToDrink(person) { // Add your code after this line - + return person.age >= 21 ? true : false; } \ No newline at end of file diff --git a/exercises/037-addArrayProperty/app.js b/exercises/037-addArrayProperty/app.js index 447c67dd7..4df511b6f 100644 --- a/exercises/037-addArrayProperty/app.js +++ b/exercises/037-addArrayProperty/app.js @@ -1,4 +1,12 @@ function addArrayProperty(obj, key, arr) { // Add your code after this line + obj[key] = arr; + return obj -} \ No newline at end of file +} + +let myObj = {}; +let myArray = [1, 3]; +console.log(myObj); // --> {} +addArrayProperty(myObj, 'myProperty', myArray); +console.log(myObj.myProperty); // --> [1, 3] \ No newline at end of file diff --git a/exercises/038-computeAreaOfARectangle/app.js b/exercises/038-computeAreaOfARectangle/app.js index 571189580..3725a65c2 100644 --- a/exercises/038-computeAreaOfARectangle/app.js +++ b/exercises/038-computeAreaOfARectangle/app.js @@ -1,6 +1,6 @@ function computeAreaOfARectangle(length, width) { // your code here - + return parseFloat(length) * parseFloat(width); } let output = computeAreaOfARectangle(10, 18); diff --git a/exercises/039-computePerimeterOfARectangle/app.js b/exercises/039-computePerimeterOfARectangle/app.js index 7e1097b42..fca575123 100644 --- a/exercises/039-computePerimeterOfARectangle/app.js +++ b/exercises/039-computePerimeterOfARectangle/app.js @@ -1,5 +1,6 @@ function computePerimeterOfARectangle(length, width) { // your code here + return (parseFloat(length) + parseFloat(width)) * 2; } let output = computePerimeterOfARectangle(5, 2); diff --git a/exercises/040-computePerimeterOfATriangle/app.js b/exercises/040-computePerimeterOfATriangle/app.js index 82e6eb746..f7d704ee0 100644 --- a/exercises/040-computePerimeterOfATriangle/app.js +++ b/exercises/040-computePerimeterOfATriangle/app.js @@ -1,5 +1,6 @@ function computePerimeterOfATriangle(side1, side2, side3) { // your code here + return parseFloat(side1) + parseFloat(side2) + parseFloat(side3); } let output = computePerimeterOfATriangle(6, 4, 10); diff --git a/exercises/041-computeTripledAreaOfARectangle/app.js b/exercises/041-computeTripledAreaOfARectangle/app.js index ce5e98336..ef9d7ca86 100644 --- a/exercises/041-computeTripledAreaOfARectangle/app.js +++ b/exercises/041-computeTripledAreaOfARectangle/app.js @@ -1,5 +1,6 @@ function computeTripledAreaOfARectangle(length, width) { // your code here + return (parseFloat(length) * parseFloat(width))*3 } diff --git a/exercises/042-computePerimeterOfACircle/app.js b/exercises/042-computePerimeterOfACircle/app.js index 2bfad5f97..e1264de65 100644 --- a/exercises/042-computePerimeterOfACircle/app.js +++ b/exercises/042-computePerimeterOfACircle/app.js @@ -1,5 +1,6 @@ function computePerimeterOfACircle(radius) { // your code here + return radius * Math.PI * 2; } diff --git a/exercises/043-computeAreaOfACircle/app.js b/exercises/043-computeAreaOfACircle/app.js index a1931f81b..e9b60fde8 100644 --- a/exercises/043-computeAreaOfACircle/app.js +++ b/exercises/043-computeAreaOfACircle/app.js @@ -1,5 +1,6 @@ function computeAreaOfACircle(radius) { // your code here + return Math.PI * (radius**2); } let output = computeAreaOfACircle(4); diff --git a/exercises/044-computePower/app.js b/exercises/044-computePower/app.js index ceb56e0f3..59b72e3cb 100644 --- a/exercises/044-computePower/app.js +++ b/exercises/044-computePower/app.js @@ -1,5 +1,6 @@ function computePower(num, exponent) { // your code here + return num ** exponent } let output = computePower(2, 3); diff --git a/exercises/045-computeSquareRoot/app.js b/exercises/045-computeSquareRoot/app.js index 2145a7bee..5e72e869e 100644 --- a/exercises/045-computeSquareRoot/app.js +++ b/exercises/045-computeSquareRoot/app.js @@ -1,5 +1,6 @@ function computeSquareRoot(num) { // your code here + return Math.sqrt(num); } let output = computeSquareRoot(9); diff --git a/exercises/046-doubleSquareRootOf/app.js b/exercises/046-doubleSquareRootOf/app.js index 75cc74300..5685126a0 100644 --- a/exercises/046-doubleSquareRootOf/app.js +++ b/exercises/046-doubleSquareRootOf/app.js @@ -1,6 +1,6 @@ function doubleSquareRootOf(num) { // your code here - + return (Math.sqrt(num)) * 2; } let output = doubleSquareRootOf(121); diff --git a/exercises/047-isEitherEvenOrAreBoth7/app.js b/exercises/047-isEitherEvenOrAreBoth7/app.js index c72dd1b3d..88f9b775c 100644 --- a/exercises/047-isEitherEvenOrAreBoth7/app.js +++ b/exercises/047-isEitherEvenOrAreBoth7/app.js @@ -1,4 +1,4 @@ function isEitherEvenOrAreBoth7(num1, num2) { // your code here - + return (num1 % 2 === 0 || num2 % 2 === 0) || (num1 === 7 && num2 === 7); } diff --git a/exercises/048-isEitherEvenAndLessThan9/app.js b/exercises/048-isEitherEvenAndLessThan9/app.js index 85320e272..8c3dd4220 100644 --- a/exercises/048-isEitherEvenAndLessThan9/app.js +++ b/exercises/048-isEitherEvenAndLessThan9/app.js @@ -1,5 +1,6 @@ function isEitherEvenAndLessThan9(num1, num2) { // your code here + return ((num1 % 2 === 0 || num2 % 2 === 0) && (num1 < 9 && num2 < 9)); } diff --git a/exercises/049-computeAverageOfNumbers/app.js b/exercises/049-computeAverageOfNumbers/app.js index 3e2df3368..827941402 100644 --- a/exercises/049-computeAverageOfNumbers/app.js +++ b/exercises/049-computeAverageOfNumbers/app.js @@ -1 +1,12 @@ // Write your function here +function computeAverageOfNumbers(numbers) { + if (numbers.length === 0) { + return 0; + } else { + let total = 0; + for (i = 0; i < numbers.length; i++) { + total += numbers[i]; + } + return total / numbers.length; + } +} \ No newline at end of file diff --git a/exercises/050-getNthElement/app.js b/exercises/050-getNthElement/app.js index 0c61fb9b3..3198abf7b 100644 --- a/exercises/050-getNthElement/app.js +++ b/exercises/050-getNthElement/app.js @@ -1,4 +1,4 @@ function getNthElement(array, n) { // Add your code after this line - + return array[n]; } diff --git a/exercises/051-getFirstElement/app.js b/exercises/051-getFirstElement/app.js index 2d285a8ba..6d49105bc 100644 --- a/exercises/051-getFirstElement/app.js +++ b/exercises/051-getFirstElement/app.js @@ -1,5 +1,6 @@ function getFirstElement(array) { // Add your code after this line + return array[0] } diff --git a/exercises/052-getLastElement/app.js b/exercises/052-getLastElement/app.js index de124d218..4705dae24 100644 --- a/exercises/052-getLastElement/app.js +++ b/exercises/052-getLastElement/app.js @@ -1,4 +1,4 @@ function getLastElement(array) { // Add your code after this line - + return array[array.length -1]; } diff --git a/exercises/053-addToFront/app.js b/exercises/053-addToFront/app.js index b7fcd6959..fece7e831 100644 --- a/exercises/053-addToFront/app.js +++ b/exercises/053-addToFront/app.js @@ -1,5 +1,7 @@ function addToFront(arr, element) { // your code here + arr.unshift(element); + return arr; } diff --git a/exercises/054-addToBack/app.js b/exercises/054-addToBack/app.js index ac69fcce3..ef22dc30a 100644 --- a/exercises/054-addToBack/app.js +++ b/exercises/054-addToBack/app.js @@ -1,5 +1,7 @@ function addToBack(arr, element) { // your code here + arr.push(element); + return arr; } diff --git a/exercises/055-joinArrays/app.js b/exercises/055-joinArrays/app.js index 3e1b15be8..7cf76c457 100644 --- a/exercises/055-joinArrays/app.js +++ b/exercises/055-joinArrays/app.js @@ -1,5 +1,6 @@ function joinArrays(arr1, arr2) { // your code here + return arr1.concat(arr2); } diff --git a/exercises/056-getElementsAfter/app.js b/exercises/056-getElementsAfter/app.js index c7020f6fa..2a218a2d1 100644 --- a/exercises/056-getElementsAfter/app.js +++ b/exercises/056-getElementsAfter/app.js @@ -1,5 +1,6 @@ function getElementsAfter(array, n) { // your code here + return array.slice(n+1,array.length) } diff --git a/exercises/057-getElementsUpTo/app.js b/exercises/057-getElementsUpTo/app.js index 4387f3611..c30d0c6db 100644 --- a/exercises/057-getElementsUpTo/app.js +++ b/exercises/057-getElementsUpTo/app.js @@ -1,7 +1,7 @@ function getElementsUpTo(array, n) { // your code here - + return array.slice(0,n); } -let output = getElementsUpTo(['a', 'b', 'c', 'd', 'e'], 3) +let output = getElementsUpTo(['a', 'b', 'c', 'd', 'e'], 3); console.log(output); // --> ['a', 'b', 'c'] diff --git a/exercises/058-removeFromFront/app.js b/exercises/058-removeFromFront/app.js index 409ef58b0..1b7ed6c2d 100644 --- a/exercises/058-removeFromFront/app.js +++ b/exercises/058-removeFromFront/app.js @@ -1,5 +1,7 @@ function removeFromFront(arr) { // your code here + arr.shift(); + return arr; } diff --git a/exercises/059-removeFromBack/app.js b/exercises/059-removeFromBack/app.js index 777da4683..5c891224d 100644 --- a/exercises/059-removeFromBack/app.js +++ b/exercises/059-removeFromBack/app.js @@ -1,5 +1,7 @@ function removeFromBack(arr) { // your code here + arr.pop(); + return arr; } diff --git a/exercises/060-removeFromFrontOfNew/app.js b/exercises/060-removeFromFrontOfNew/app.js index 893cf2a18..75fcc669c 100644 --- a/exercises/060-removeFromFrontOfNew/app.js +++ b/exercises/060-removeFromFrontOfNew/app.js @@ -1,5 +1,6 @@ function removeFromFrontOfNew(arr) { // your code here + return arr.slice(1,arr.length); } diff --git a/exercises/061-removeFromBackOfNew/app.js b/exercises/061-removeFromBackOfNew/app.js index df89dcd53..e7e7380e5 100644 --- a/exercises/061-removeFromBackOfNew/app.js +++ b/exercises/061-removeFromBackOfNew/app.js @@ -1,5 +1,6 @@ function removeFromBackOfNew(arr) { // your code here + return arr.slice(0,arr.length-1); } diff --git a/exercises/062-countCharacter/app.js b/exercises/062-countCharacter/app.js index 29557e7c7..103e7db73 100644 --- a/exercises/062-countCharacter/app.js +++ b/exercises/062-countCharacter/app.js @@ -1,6 +1,10 @@ function countCharacter(str, char) { // your code here - + let total = 0 + for(let i = 0; i < str.length; i++){ + str[i] == char ? total+=1 : total+=0; + } + return total } let output = countCharacter('I am a hacker', 'a'); diff --git a/exercises/063-getAllLetters/app.js b/exercises/063-getAllLetters/app.js index 7f5dc731b..67ac82cd8 100644 --- a/exercises/063-getAllLetters/app.js +++ b/exercises/063-getAllLetters/app.js @@ -1,5 +1,10 @@ function getAllLetters(str) { // your code here + let array = []; + for(let i=0;i num){ + delete obj[key]; + } + } +} + let obj = { a: 8, b: 2, c: 'montana' -} - -function removeNumbersLargerThan(num, obj) { - // your code here - -} + } + removeNumbersLargerThan(5, obj); + console.log(obj); // --> { b: 2, c: 'montana' } diff --git a/exercises/068-removeNumbersLessThan/app.js b/exercises/068-removeNumbersLessThan/app.js index bed771763..1d7c27976 100644 --- a/exercises/068-removeNumbersLessThan/app.js +++ b/exercises/068-removeNumbersLessThan/app.js @@ -6,5 +6,10 @@ let obj = { function removeNumbersLessThan(num, obj) { // your code here + for(key in obj){ + if(Number.isInteger(obj[key]) && obj[key] < num){ + delete obj[key]; + } + } } diff --git a/exercises/069-removeStringValuesLongerThan/app.js b/exercises/069-removeStringValuesLongerThan/app.js index 062756977..8db2f63e8 100644 --- a/exercises/069-removeStringValuesLongerThan/app.js +++ b/exercises/069-removeStringValuesLongerThan/app.js @@ -1,6 +1,13 @@ function removeStringValuesLongerThan(num, obj) { // your code here - + for (key in obj) { + if (typeof (obj[key]) == 'string') { + if (obj[key].length > num) { + delete obj[key]; + } + } + } + } let obj = { diff --git a/exercises/070-removeEvenValues/app.js b/exercises/070-removeEvenValues/app.js index 1d82a7105..903af06fa 100644 --- a/exercises/070-removeEvenValues/app.js +++ b/exercises/070-removeEvenValues/app.js @@ -1,6 +1,11 @@ function removeEvenValues(obj) { - // your code here - + // your code here + for (key in obj) { + if (Number.isInteger(obj[key]) && obj[key] % 2 === 0) { + delete obj[key]; + } + } + } let obj = { diff --git a/exercises/071-countNumberOfKeys/app.js b/exercises/071-countNumberOfKeys/app.js index 35a475c97..54c2187b0 100644 --- a/exercises/071-countNumberOfKeys/app.js +++ b/exercises/071-countNumberOfKeys/app.js @@ -9,6 +9,11 @@ let obj = { function countNumberOfKeys(obj) { // your code here + let total = 0; + for(key in obj){ + total+=1; + } + return total; } diff --git a/exercises/072-removeOddValues/app.js b/exercises/072-removeOddValues/app.js index a5a19c538..7190be287 100644 --- a/exercises/072-removeOddValues/app.js +++ b/exercises/072-removeOddValues/app.js @@ -1,5 +1,10 @@ function removeOddValues(obj) { // your code here + for (key in obj) { + if (Number.isInteger(obj[key]) && obj[key] % 2 !== 0) { + delete obj[key]; + } + } } diff --git a/exercises/073-removeArrayValues/app.js b/exercises/073-removeArrayValues/app.js index 295a2a3ae..c6bea8fc8 100644 --- a/exercises/073-removeArrayValues/app.js +++ b/exercises/073-removeArrayValues/app.js @@ -1,4 +1,17 @@ function removeArrayValues(obj) { // your code here - -} \ No newline at end of file + for (key in obj) { + if (typeof (obj[key]) == 'object') { + delete obj[key]; + } + } + +} + +let obj = { + a: [1, 3, 4], + b: 2, + c: ['hi', 'there'] + } + removeArrayValues(obj); + console.log(obj); // --> { b: 2 } \ No newline at end of file diff --git a/exercises/074-removeNumberValues/app.js b/exercises/074-removeNumberValues/app.js index 7bf955613..b4671fbb7 100644 --- a/exercises/074-removeNumberValues/app.js +++ b/exercises/074-removeNumberValues/app.js @@ -1,6 +1,10 @@ function removeNumberValues(obj) { // your code here - + for (key in obj) { + if (typeof (obj[key]) == 'number') { + delete obj[key]; + } + } } let obj = { diff --git a/exercises/075-removeStringValues/app.js b/exercises/075-removeStringValues/app.js index 32d2afaad..646689dcd 100644 --- a/exercises/075-removeStringValues/app.js +++ b/exercises/075-removeStringValues/app.js @@ -1,6 +1,10 @@ function removeStringValues(obj) { // your code here - + for (key in obj) { + if (typeof (obj[key]) == 'string') { + delete obj[key]; + } + } } let obj = { diff --git a/exercises/076-convertDoubleSpaceToSingle/app.js b/exercises/076-convertDoubleSpaceToSingle/app.js index ed0a2e7cf..76d2f6e70 100644 --- a/exercises/076-convertDoubleSpaceToSingle/app.js +++ b/exercises/076-convertDoubleSpaceToSingle/app.js @@ -1,5 +1,6 @@ function convertDoubleSpaceToSingle(str) { // your code here + return str.replaceAll(" ", " ") } diff --git a/exercises/077-areValidCredentials/app.js b/exercises/077-areValidCredentials/app.js index 3e2df3368..2ce4ae6e4 100644 --- a/exercises/077-areValidCredentials/app.js +++ b/exercises/077-areValidCredentials/app.js @@ -1 +1,4 @@ // Write your function here +const areValidCredentials = (username, password)=>{ + return username.length>3 && password.length>=8; +} diff --git a/exercises/078-getIndexOf/app.js b/exercises/078-getIndexOf/app.js index 3e2df3368..d325f66db 100644 --- a/exercises/078-getIndexOf/app.js +++ b/exercises/078-getIndexOf/app.js @@ -1 +1,10 @@ // Write your function here +function getIndexOf(char, str){ + for(let i=0;i 2 diff --git a/exercises/079-findMinLengthOfThreeWords/app.js b/exercises/079-findMinLengthOfThreeWords/app.js index 6ebc804ae..c183464e4 100644 --- a/exercises/079-findMinLengthOfThreeWords/app.js +++ b/exercises/079-findMinLengthOfThreeWords/app.js @@ -1 +1,4 @@ -// Write your function here \ No newline at end of file +// Write your function here +function findMinLengthOfThreeWords(word1,word2,word3){ + return Math.min(word1.length,word2.length,word3.length) +} \ No newline at end of file diff --git a/exercises/080-findMaxLengthOfThreeWords/app.js b/exercises/080-findMaxLengthOfThreeWords/app.js index 6ebc804ae..988177510 100644 --- a/exercises/080-findMaxLengthOfThreeWords/app.js +++ b/exercises/080-findMaxLengthOfThreeWords/app.js @@ -1 +1,4 @@ -// Write your function here \ No newline at end of file +// Write your function here +function findMaxLengthOfThreeWords(word1,word2,word3){ + return Math.max(word1.length,word2.length,word3.length) +} \ No newline at end of file diff --git a/exercises/081-repeatString/app.js b/exercises/081-repeatString/app.js index 36391aad4..7e959ceef 100644 --- a/exercises/081-repeatString/app.js +++ b/exercises/081-repeatString/app.js @@ -1,6 +1,6 @@ function repeatString(string, num) { // your code here - + return string.repeat(num); } let output = repeatString('code', 3); diff --git a/exercises/082-getLongestOfThreeWords/app.js b/exercises/082-getLongestOfThreeWords/app.js index 42b3ac7d6..ac0b1b287 100644 --- a/exercises/082-getLongestOfThreeWords/app.js +++ b/exercises/082-getLongestOfThreeWords/app.js @@ -1,5 +1,10 @@ function getLongestOfThreeWords(word1, word2, word3) { // your code here + let longest = ""; + if(word1.length > longest.length) longest=word1; + if(word2.length > longest.length) longest=word2; + if(word3.length > longest.length) longest=word3; + return longest; } diff --git a/exercises/083-findShortestOfThreeWords/app.js b/exercises/083-findShortestOfThreeWords/app.js index 7f9005ba1..b7f2c99a4 100644 --- a/exercises/083-findShortestOfThreeWords/app.js +++ b/exercises/083-findShortestOfThreeWords/app.js @@ -1,5 +1,9 @@ function findShortestOfThreeWords(word1, word2, word3) { // your code here + let shortest = word1; + if(word2.length < shortest.length) shortest=word2; + if(word3.length < shortest.length) shortest=word3; + return shortest; } diff --git a/exercises/084-joinThreeArrays/app.js b/exercises/084-joinThreeArrays/app.js index 13bb8c197..1213fd39d 100644 --- a/exercises/084-joinThreeArrays/app.js +++ b/exercises/084-joinThreeArrays/app.js @@ -1,4 +1,6 @@ function joinThreeArrays(arr1, arr2, arr3) { // your code here + let newArray = arr1.concat(arr2, arr3); + return newArray; } \ No newline at end of file diff --git a/exercises/085-addToFrontOfNew/app.js b/exercises/085-addToFrontOfNew/app.js index 2e213064c..893aec98e 100644 --- a/exercises/085-addToFrontOfNew/app.js +++ b/exercises/085-addToFrontOfNew/app.js @@ -1,5 +1,7 @@ function addToFrontOfNew(arr, element) { // your code here + let newArr = [element, ...arr]; + return newArr; } diff --git a/exercises/086-addToBackOfNew/app.js b/exercises/086-addToBackOfNew/app.js index ad99f9609..3abe84695 100644 --- a/exercises/086-addToBackOfNew/app.js +++ b/exercises/086-addToBackOfNew/app.js @@ -1,5 +1,7 @@ function addToBackOfNew(arr, element) { // your code here + let newArr = [...arr, element]; + return newArr; } diff --git a/exercises/087-getAllElementsButNth/app.js b/exercises/087-getAllElementsButNth/app.js index b5986c5b2..770c20568 100644 --- a/exercises/087-getAllElementsButNth/app.js +++ b/exercises/087-getAllElementsButNth/app.js @@ -1,5 +1,7 @@ function getAllElementsButNth(array, n) { // your code here + array.splice(n,n); + return array; } diff --git a/exercises/087-getAllElementsButNth/solution.hide.js b/exercises/087-getAllElementsButNth/solution.hide.js index 047431476..04461c14d 100644 --- a/exercises/087-getAllElementsButNth/solution.hide.js +++ b/exercises/087-getAllElementsButNth/solution.hide.js @@ -1,7 +1,15 @@ function getAllElementsButNth(array, n) { // your code here - array.splice(n, 1); - return array + function getAllElementsButNth(array, n) { + // your code here + array.splice(n,n); + return array; + + } + + let output = getAllElementsButNth(['a', 'b', 'c'], 1); + console.log(output); // --> ['a', 'c'] + } let output = getAllElementsButNth(['a', 'b', 'c'], 1); diff --git a/exercises/088-keep/app.js b/exercises/088-keep/app.js index 3e2df3368..11b3ce3f6 100644 --- a/exercises/088-keep/app.js +++ b/exercises/088-keep/app.js @@ -1 +1,7 @@ // Write your function here +function keep(arr,index){ + return arr.filter((number)=>number==index); +} + +let output = keep([1, 2, 3, 2, 1], 2) +console.log(output); // --> [2, 2] \ No newline at end of file diff --git a/exercises/089-removeElement/app.js b/exercises/089-removeElement/app.js index 3e2df3368..3e8794f5e 100644 --- a/exercises/089-removeElement/app.js +++ b/exercises/089-removeElement/app.js @@ -1 +1,5 @@ // Write your function here +function removeElement(arr,index){ + let newArr = arr.filter((number)=>number!==index); + return newArr; +} diff --git a/exercises/090-filterOddLengthWords/app.js b/exercises/090-filterOddLengthWords/app.js index ec065e3e4..f8de63ccb 100644 --- a/exercises/090-filterOddLengthWords/app.js +++ b/exercises/090-filterOddLengthWords/app.js @@ -1,5 +1,6 @@ function filterOddLengthWords(words) { // your code here + return words.filter((word)=>word.length % 2 !==0); } diff --git a/exercises/091-filterEvenLengthWords/app.js b/exercises/091-filterEvenLengthWords/app.js index 88104f97b..24a85618a 100644 --- a/exercises/091-filterEvenLengthWords/app.js +++ b/exercises/091-filterEvenLengthWords/app.js @@ -1,5 +1,6 @@ function filterEvenLengthWords(words) { // your code here + return words.filter((word)=>word.length%2==0); } diff --git a/exercises/092-getFirstElementOfProperty/app.js b/exercises/092-getFirstElementOfProperty/app.js index 3e2df3368..1c9d42a1c 100644 --- a/exercises/092-getFirstElementOfProperty/app.js +++ b/exercises/092-getFirstElementOfProperty/app.js @@ -1 +1,16 @@ // Write your function here +function getFirstElementOfProperty(obj, key){ + for(prop in obj){ + if(prop === key){ + return obj.key[0] + } + } +} + +let obj = { + key: [1, 2, 4], + edad: 23, + nombre:'wilfredo' + }; + let output = getFirstElementOfProperty(obj, 'key'); + console.log(output); \ No newline at end of file diff --git a/exercises/093-getNthElementOfProperty/app.js b/exercises/093-getNthElementOfProperty/app.js index 3e2df3368..2a2119fbc 100644 --- a/exercises/093-getNthElementOfProperty/app.js +++ b/exercises/093-getNthElementOfProperty/app.js @@ -1 +1,14 @@ // Write your function here +function getNthElementOfProperty(obj,key,n){ + for(prop in obj){ + if(prop == key){ + return obj.key[n]; + } + } +} + +let obj = { + key: [1, 2, 6] + }; + let output = getNthElementOfProperty(obj, 'key', 2); + console.log(output); // --> 2 diff --git a/exercises/094-getLastElementOfProperty/app.js b/exercises/094-getLastElementOfProperty/app.js index 3e2df3368..7cd94c46e 100644 --- a/exercises/094-getLastElementOfProperty/app.js +++ b/exercises/094-getLastElementOfProperty/app.js @@ -1 +1,14 @@ // Write your function here +function getLastElementOfProperty(obj,key){ + for(k in obj){ + if(k == key){ + return obj.key[obj.key.length -1]; + } + } +} + +let obj = { + key: [1, 2, 5] + }; + let output = getLastElementOfProperty(obj, 'key'); + console.log(output); // --> 5 diff --git a/exercises/095-getElementsThatEqual10AtProperty/app.js b/exercises/095-getElementsThatEqual10AtProperty/app.js index 3e2df3368..0c04ec85a 100644 --- a/exercises/095-getElementsThatEqual10AtProperty/app.js +++ b/exercises/095-getElementsThatEqual10AtProperty/app.js @@ -1 +1,16 @@ // Write your function here +function getElementsThatEqual10AtProperty(obj, key) { + if(!obj[key] || obj[key].length == 0 || !Array.isArray(obj[key])) { + return [] + } + + let arr = obj[key] + let newArr = [] + + arr.forEach(e => { + if(e === 10) { + newArr.push(e) + } + }) + return newArr; +} diff --git a/exercises/096-getElementsLessThanOneHundredAtProperty/app.js b/exercises/096-getElementsLessThanOneHundredAtProperty/app.js index 3e2df3368..1e943a1c4 100644 --- a/exercises/096-getElementsLessThanOneHundredAtProperty/app.js +++ b/exercises/096-getElementsLessThanOneHundredAtProperty/app.js @@ -1 +1,15 @@ -// Write your function here +function getElementsLessThan100AtProperty(obj, key) { + if(!obj[key] || obj[key].length == 0 || !Array.isArray(obj[key])) { + return [] + } + + let arr = obj[key] + let newArr = [] + + arr.forEach(e => { + if(e < 100) { + newArr.push(e) + } + }) + return newArr; +} diff --git a/exercises/097-getElementsGreaterThanTenAtProperty/app.js b/exercises/097-getElementsGreaterThanTenAtProperty/app.js index 3e2df3368..95002ec9f 100644 --- a/exercises/097-getElementsGreaterThanTenAtProperty/app.js +++ b/exercises/097-getElementsGreaterThanTenAtProperty/app.js @@ -1 +1,15 @@ -// Write your function here +function getElementsGreaterThan10AtProperty(obj, key) { + if(!obj[key] || obj[key].length == 0 || !Array.isArray(obj[key])) { + return [] + } + + let arr = obj[key] + let newArr = [] + + arr.forEach(e => { + if(e >10) { + newArr.push(e) + } + }) + return newArr; +} diff --git a/exercises/098-getOddLengthWordsAtProperty/app.js b/exercises/098-getOddLengthWordsAtProperty/app.js index 3e2df3368..80ec1baa9 100644 --- a/exercises/098-getOddLengthWordsAtProperty/app.js +++ b/exercises/098-getOddLengthWordsAtProperty/app.js @@ -1 +1,16 @@ // Write your function here +function getOddLengthWordsAtProperty(obj, key) { + if(!obj[key] || obj[key].length == 0 || !Array.isArray(obj[key])) { + return [] + } + + let arr = obj[key] + let newArr = [] + + arr.forEach(e => { + if(e.length %2!==0) { + newArr.push(e) + } + }) + return newArr; +} diff --git a/exercises/099-getAverageOfElementsAtProperty/app.js b/exercises/099-getAverageOfElementsAtProperty/app.js index 8339aa1d1..fbcb5131e 100644 --- a/exercises/099-getAverageOfElementsAtProperty/app.js +++ b/exercises/099-getAverageOfElementsAtProperty/app.js @@ -1,4 +1,14 @@ function getAverageOfElementsAtProperty(obj, key) { // your code here + if ((!obj[key] || obj[key].length == 0) || !Array.isArray(obj[key])) { + return 0; + } + let total = 0; + let contador = 0; + obj[key].forEach((n) => { + contador += 1; + total += n; + }) + return total / contador; } \ No newline at end of file diff --git a/exercises/100-getEvenLengthWordsAtProperty/app.js b/exercises/100-getEvenLengthWordsAtProperty/app.js index 1ba09c698..301bff5ed 100644 --- a/exercises/100-getEvenLengthWordsAtProperty/app.js +++ b/exercises/100-getEvenLengthWordsAtProperty/app.js @@ -1,5 +1,15 @@ function getEvenLengthWordsAtProperty(obj, key) { // your code here + if((!obj[key] || obj[key].length == 0) || !Array.isArray(obj[key])){ + return []; + } + let evenArr = [] + obj[key].forEach(element => { + if(element.length%2==0){ + evenArr.push(element); + } + }); + return evenArr; } diff --git a/exercises/101-getOddElementsAtProperty/app.js b/exercises/101-getOddElementsAtProperty/app.js index 163577f1c..0d98f3c13 100644 --- a/exercises/101-getOddElementsAtProperty/app.js +++ b/exercises/101-getOddElementsAtProperty/app.js @@ -1,5 +1,9 @@ function getOddElementsAtProperty(obj, key) { // your code here + if((!obj[key] || obj[key].length == 0) || !Array.isArray(obj[key])){ + return []; + } + return obj[key].filter((number)=>number%2!==0); } diff --git a/exercises/102-getEvenElementsAtProperty/app.js b/exercises/102-getEvenElementsAtProperty/app.js index 28b5d8a00..038f3297c 100644 --- a/exercises/102-getEvenElementsAtProperty/app.js +++ b/exercises/102-getEvenElementsAtProperty/app.js @@ -1,5 +1,9 @@ function getEvenElementsAtProperty(obj, key) { // your code here + if((!obj[key] || obj[key].length == 0) || !Array.isArray(obj[key])){ + return []; + } + return obj[key].filter((number)=>number%2==0); } diff --git a/exercises/103-getSquaredElementsAtProperty/app.js b/exercises/103-getSquaredElementsAtProperty/app.js index e1ca8f4c6..9bdcb19b3 100644 --- a/exercises/103-getSquaredElementsAtProperty/app.js +++ b/exercises/103-getSquaredElementsAtProperty/app.js @@ -1,5 +1,9 @@ function getSquaredElementsAtProperty(obj, key) { // your code here + if((!obj[key] || obj[key].length == 0) || !Array.isArray(obj[key])){ + return []; + } + return obj[key].map((number)=>number**2); } diff --git a/exercises/104-getSmallestElementAtProperty/app.js b/exercises/104-getSmallestElementAtProperty/app.js index 93f9caf58..df339ce3c 100644 --- a/exercises/104-getSmallestElementAtProperty/app.js +++ b/exercises/104-getSmallestElementAtProperty/app.js @@ -1,5 +1,10 @@ function getSmallestElementAtProperty(obj, key) { // your code here + if((!obj[key] || obj[key].length == 0) || !Array.isArray(obj[key])){ + return []; + } + return Math.min(...obj[key]); + } diff --git a/exercises/105-getLargestElementAtProperty/app.js b/exercises/105-getLargestElementAtProperty/app.js index 722724828..8c906b6a0 100644 --- a/exercises/105-getLargestElementAtProperty/app.js +++ b/exercises/105-getLargestElementAtProperty/app.js @@ -1,5 +1,9 @@ function getLargestElementAtProperty(obj, key) { // your code here + if((!obj[key] || obj[key].length == 0) || !Array.isArray(obj[key])){ + return []; + } + return Math.max(...obj[key]); } diff --git a/exercises/106-getAllButLastElementOfProperty/app.js b/exercises/106-getAllButLastElementOfProperty/app.js index 096f5ac8e..ad290b9f2 100644 --- a/exercises/106-getAllButLastElementOfProperty/app.js +++ b/exercises/106-getAllButLastElementOfProperty/app.js @@ -1,5 +1,10 @@ function getAllButLastElementOfProperty(obj, key) { // your code here + if((!obj[key] || obj[key].length == 0) || !Array.isArray(obj[key])){ + return []; + } + return obj[key].slice(0,obj[key].length -1); + } diff --git a/exercises/107-getElementOfArrayProperty/app.js b/exercises/107-getElementOfArrayProperty/app.js index c54881d29..663a16567 100644 --- a/exercises/107-getElementOfArrayProperty/app.js +++ b/exercises/107-getElementOfArrayProperty/app.js @@ -1,5 +1,9 @@ function getElementOfArrayProperty(obj, key, index) { // your code here + if((!obj[key]|| obj[key].length==0 ) || (!Array.isArray(obj[key])|| !obj[key][index])){ + return undefined; + } + return obj[key][index]; } diff --git a/exercises/108-getProductOfAllElementsAtProperty/app.js b/exercises/108-getProductOfAllElementsAtProperty/app.js index 6c619b509..781287bb4 100644 --- a/exercises/108-getProductOfAllElementsAtProperty/app.js +++ b/exercises/108-getProductOfAllElementsAtProperty/app.js @@ -1,5 +1,9 @@ function getProductOfAllElementsAtProperty(obj, key) { // your code here + if((!obj[key] || obj[key].length == 0) || !Array.isArray(obj[key])){ + return 0; + } + return obj[key].reduce((accumulator, currentValue) => accumulator * currentValue); } diff --git a/exercises/109-Select/app.js b/exercises/109-Select/app.js index 3e2df3368..16d9dda9a 100644 --- a/exercises/109-Select/app.js +++ b/exercises/109-Select/app.js @@ -1 +1,20 @@ // Write your function here +function select(arr,obj){ + let newObj={}; + for(k in obj){ + if(arr.includes(k)){ + newObj[k] = obj[k]; + } + } + return newObj; +} + +let arr = ['a', 'c', 'e']; +let obj = { + a: 1, + b: 2, + c: 3, + d: 4 +}; +let output = select(arr, obj); +console.log(output); // --> { a: 1, c: 3 } diff --git a/exercises/110-getSumOfAllElementsAtProperty/app.js b/exercises/110-getSumOfAllElementsAtProperty/app.js index 3a48d860a..e9fbada71 100644 --- a/exercises/110-getSumOfAllElementsAtProperty/app.js +++ b/exercises/110-getSumOfAllElementsAtProperty/app.js @@ -1,6 +1,10 @@ function getSumOfAllElementsAtProperty(obj, key) { // your code here - + if ((!obj[key] || obj[key].length == 0) || !Array.isArray(obj[key])) { + return 0; + } + return obj[key].reduce((accumulator,currentValue)=>accumulator+currentValue); + } let obj = { diff --git a/exercises/111-countAllCharacters/app.js b/exercises/111-countAllCharacters/app.js index 3e2df3368..fd1c6a989 100644 --- a/exercises/111-countAllCharacters/app.js +++ b/exercises/111-countAllCharacters/app.js @@ -1 +1,15 @@ // Write your function here +function countAllCharacters(str){ + let newObj={}; + for(char in str){ + if(!(str[char] in newObj)){ + newObj[str[char]] = 1 + }else{ + newObj[str[char]] +=1; + } + } + return newObj; +} + +let output = countAllCharacters('banana'); +console.log(output); // --> {b: 1, a: 3, n: 2} diff --git a/exercises/112-getLengthOfLongestElement/app.js b/exercises/112-getLengthOfLongestElement/app.js index bbb1c23cd..98d0f6df3 100644 --- a/exercises/112-getLengthOfLongestElement/app.js +++ b/exercises/112-getLengthOfLongestElement/app.js @@ -1,5 +1,15 @@ function getLengthOfLongestElement(arr) { // Your code here + if(arr.length == 0){ + return 0; + } + let maxLen = 0; + arr.forEach(element => { + if(element.length > maxLen){ + maxLen = element.length; + } + }); + return maxLen; } diff --git a/exercises/113-squareElements/app.js b/exercises/113-squareElements/app.js index bd4906062..0225af814 100644 --- a/exercises/113-squareElements/app.js +++ b/exercises/113-squareElements/app.js @@ -1,6 +1,7 @@ function squareElements(arr) { // your code here - + return arr.map((num) => Math.pow(num, 2)); + } let output = squareElements([1, 2, 3]); diff --git a/exercises/114-filterOddElements/app.js b/exercises/114-filterOddElements/app.js index 114d08f65..fa07c602e 100644 --- a/exercises/114-filterOddElements/app.js +++ b/exercises/114-filterOddElements/app.js @@ -1,6 +1,7 @@ function filterOddElements(arr) { // your code here - + return arr.filter((num) => num % 2 != 0); + } let output = filterOddElements([1, 2, 3, 4, 5]); diff --git a/exercises/115-computeProductOfAllElements/app.js b/exercises/115-computeProductOfAllElements/app.js index 107ba7f60..c8a204030 100644 --- a/exercises/115-computeProductOfAllElements/app.js +++ b/exercises/115-computeProductOfAllElements/app.js @@ -1,5 +1,10 @@ function computeProductOfAllElements(arr) { // your code here + if(!(arr.length>0)){ + return 0; + }else{ + return arr.reduce((contador,valorInicial)=>contador*valorInicial); + } } diff --git a/exercises/116-filterEvenElements/app.js b/exercises/116-filterEvenElements/app.js index 4d394d525..18d4dce9b 100644 --- a/exercises/116-filterEvenElements/app.js +++ b/exercises/116-filterEvenElements/app.js @@ -1,5 +1,6 @@ function filterEvenElements(arr) { // your code here + return arr.filter((num)=>num%2==0); } diff --git a/exercises/117-getLengthOfShortestElement/app.js b/exercises/117-getLengthOfShortestElement/app.js index 56efecb14..10ff7d8ee 100644 --- a/exercises/117-getLengthOfShortestElement/app.js +++ b/exercises/117-getLengthOfShortestElement/app.js @@ -1,5 +1,15 @@ function getLengthOfShortestElement(arr) { // your code here + if(arr.length == 0){ + return 0; + } + let minLen = arr[0].length; + arr.forEach(element => { + if(element.length < minLen){ + minLen = element.length; + } + }); + return minLen; } diff --git a/exercises/118-getLongestElement/app.js b/exercises/118-getLongestElement/app.js index 2fd4f49d0..21ec934fb 100644 --- a/exercises/118-getLongestElement/app.js +++ b/exercises/118-getLongestElement/app.js @@ -1,7 +1,15 @@ function getLongestElement(arr) { // your code here + if (arr.length < 1) return ''; -} - -let output = getLongestElement(['one', 'two', 'three']); -console.log(output); // --> 'three' + let aux = ''; + for (let e of arr) { + if (e.length > aux.length) aux = e; + } + + return aux; + } + + let output = getLongestElement(['one', 'two', 'three']); + console.log(output); // --> 'three' + \ No newline at end of file diff --git a/exercises/119-findSmallestElement/app.js b/exercises/119-findSmallestElement/app.js index 4126bd57d..512c0a5f1 100644 --- a/exercises/119-findSmallestElement/app.js +++ b/exercises/119-findSmallestElement/app.js @@ -1,6 +1,10 @@ function findSmallestElement(arr) { // your code here - + if(arr.length>0){ + return Math.min(...arr); + }else{ + return 0; + } } let output = findSmallestElement([4, 1, 9, 10]); diff --git a/exercises/120-findShortestElement/app.js b/exercises/120-findShortestElement/app.js index bff07f040..f8ab8572a 100644 --- a/exercises/120-findShortestElement/app.js +++ b/exercises/120-findShortestElement/app.js @@ -1,7 +1,18 @@ function findShortestElement(arr) { // your code here + if (arr.length > 0) { + let shortest = arr[0]; + for (element in arr) { + if (arr[element].length < shortest.length) { + shortest = arr[element]; + } + } + return shortest; + } else { + return ''; + } } -let output = findShortestElement(['a', 'two', 'three']); +let output = findShortestElement(['two', 'three', 'a']); console.log(output); // --> 'a' \ No newline at end of file diff --git a/exercises/121-getLargestElement/app.js b/exercises/121-getLargestElement/app.js index 12ee2fc07..57b8d13ab 100644 --- a/exercises/121-getLargestElement/app.js +++ b/exercises/121-getLargestElement/app.js @@ -1,5 +1,10 @@ function getLargestElement(arr) { // your code here + if(arr.length>0){ + return Math.max(...arr); + }else{ + return 0; + } } diff --git a/exercises/122-computeSumOfAllElements/app.js b/exercises/122-computeSumOfAllElements/app.js index 606800a9f..8a91f330f 100644 --- a/exercises/122-computeSumOfAllElements/app.js +++ b/exercises/122-computeSumOfAllElements/app.js @@ -1,5 +1,6 @@ function computeSumOfAllElements(arr) { // your code here + return arr.reduce((a,b)=>a+b); } diff --git a/exercises/123-joinArraysOfArrays/app.js b/exercises/123-joinArraysOfArrays/app.js index 16b69107c..883bc8b2f 100644 --- a/exercises/123-joinArraysOfArrays/app.js +++ b/exercises/123-joinArraysOfArrays/app.js @@ -1,6 +1,17 @@ function joinArrayOfArrays(arr) { // your code here - + //let newArray = [] + // for(array in arr){ + // for(subArr in arr[array]){ + // newArray.push(arr[array][subArr]) + // } + // } + // return newArray; + let aux = []; + for (let e of arr) { + aux = aux.concat(e); + } + return aux; } let output = joinArrayOfArrays([ diff --git a/exercises/124-findShortestWordAmongMixedElements/app.js b/exercises/124-findShortestWordAmongMixedElements/app.js index 656547df3..e8194172d 100644 --- a/exercises/124-findShortestWordAmongMixedElements/app.js +++ b/exercises/124-findShortestWordAmongMixedElements/app.js @@ -1,7 +1,18 @@ function findShortestWordAmongMixedElements(arr) { // your code here - -} - -let output = findShortestWordAmongMixedElements([4, 'two', 2, 'three']); -console.log(output); // --> 'two' + let shortestWord = ''; + let shortestLength = Infinity; + + for (let element of arr) { + if (typeof element === 'string' && element.length < shortestLength) { + shortestWord = element; + shortestLength = element.length; + } + } + + return shortestWord; + } + + let output = findShortestWordAmongMixedElements([4, 'two', 2, 'three']); + console.log(output); // --> 'two' + \ No newline at end of file diff --git a/exercises/125-findSmallestnumberAmongMixedElements/app.js b/exercises/125-findSmallestnumberAmongMixedElements/app.js index 44ce5626f..be4113942 100644 --- a/exercises/125-findSmallestnumberAmongMixedElements/app.js +++ b/exercises/125-findSmallestnumberAmongMixedElements/app.js @@ -1,6 +1,18 @@ function findSmallestNumberAmongMixedElements(arr) { // your code here - + let smallestNumber = Infinity; + + for (let element of arr) { + if (typeof element === 'number' && element < smallestNumber) { + smallestNumber = element; + } + } + + if (smallestNumber === Infinity) { + return 0; + } else { + return smallestNumber; + } } let output = findSmallestNumberAmongMixedElements([4, 'lincoln', 9, 'octopus']); diff --git a/exercises/126-getLongestWordOfMixedElements/app.js b/exercises/126-getLongestWordOfMixedElements/app.js index 1432a201c..7a02b9332 100644 --- a/exercises/126-getLongestWordOfMixedElements/app.js +++ b/exercises/126-getLongestWordOfMixedElements/app.js @@ -1,7 +1,15 @@ function getLongestWordOfMixedElements(arr) { // your code here - -} + let longestWord = ''; + + for (let element of arr) { + if (typeof element === 'string' && element.length > longestWord.length) { + longestWord = element; + } + } + + return longestWord; + } let output = getLongestWordOfMixedElements([3, 'word', 5, 'up', 3, 1]); console.log(output); // --> 'word' diff --git a/exercises/127-getLargestNumberAmongMixedElements/app.js b/exercises/127-getLargestNumberAmongMixedElements/app.js index 2599e198c..08556f402 100644 --- a/exercises/127-getLargestNumberAmongMixedElements/app.js +++ b/exercises/127-getLargestNumberAmongMixedElements/app.js @@ -1,7 +1,20 @@ function getLargestNumberAmongMixedElements(arr) { // your code here - -} - -let output = getLargestNumberAmongMixedElements([3, 'word', 5, 'up', 3, 1]); -console.log(output); // --> 5 + let largestNumber = -Infinity; + + for (let element of arr) { + if (typeof element === 'number' && element > largestNumber) { + largestNumber = element; + } + } + + if (largestNumber === -Infinity) { + return 0; + } else { + return largestNumber; + } + } + + let output = getLargestNumberAmongMixedElements([3, 'word', 5, 'up', 3, 1]); + console.log(output); // --> 5 + \ No newline at end of file diff --git a/exercises/128-averageIntegers/app.js b/exercises/128-averageIntegers/app.js index c9fb36856..56f3c2b6b 100644 --- a/exercises/128-averageIntegers/app.js +++ b/exercises/128-averageIntegers/app.js @@ -1,10 +1,12 @@ function average(arr) { // your code here + return ((sum(arr))/arr.length); } function sum(arr) { // your code here + return arr.reduce((accumulator,initialValue)=>accumulator+initialValue); } diff --git a/exercises/129-calculateBillTotal/app.js b/exercises/129-calculateBillTotal/app.js index a807a9280..0b7691836 100644 --- a/exercises/129-calculateBillTotal/app.js +++ b/exercises/129-calculateBillTotal/app.js @@ -1,5 +1,7 @@ function calculateBillTotal(preTaxAndTipAmount) { // your code here + return (preTaxAndTipAmount + (preTaxAndTipAmount*0.095) + (preTaxAndTipAmount*0.15)) + } diff --git a/exercises/130-multiplyBetween/app.js b/exercises/130-multiplyBetween/app.js index bcd2f469f..695e574b7 100644 --- a/exercises/130-multiplyBetween/app.js +++ b/exercises/130-multiplyBetween/app.js @@ -1,5 +1,14 @@ function multiplyBetween(num1, num2) { // your code here + if(num2 accumulator * initialValue); + } } diff --git a/exercises/131-computeSumBetween/app.js b/exercises/131-computeSumBetween/app.js index ef0828c81..e62b8a6c8 100644 --- a/exercises/131-computeSumBetween/app.js +++ b/exercises/131-computeSumBetween/app.js @@ -1,5 +1,14 @@ function computeSumBetween(num1, num2) { // your code here + if (num2 < num1) { + return 0; + } else { + let arr = [] + for (let i = num1; i < num2; i++) { + arr.push(i); + } + return arr.reduce((accumulator, initialValue) => accumulator + initialValue); + } } diff --git a/exercises/132-computeSummationToN/app.js b/exercises/132-computeSummationToN/app.js index cba6e2825..bbc14b508 100644 --- a/exercises/132-computeSummationToN/app.js +++ b/exercises/132-computeSummationToN/app.js @@ -1,6 +1,10 @@ function computeSummationToN(n) { // your code here - + let total=0 + for (let i = 0; i <= n; i++) { + total+=i; + } + return total } let output = computeSummationToN(6); diff --git a/exercises/133-convertScoreToGrade/app.js b/exercises/133-convertScoreToGrade/app.js index aea498a88..0345d6514 100644 --- a/exercises/133-convertScoreToGrade/app.js +++ b/exercises/133-convertScoreToGrade/app.js @@ -1,6 +1,21 @@ function convertScoreToGrade(score) { // your code here - + if (score > 100 || score < 0) { + return 'INVALID SCORE'; + } else { + if (score <= 59 && score > 0) { + return 'F'; + } else if (score >= 60 && score <= 69) { + return 'D'; + } else if (score >= 70 && score <= 79) { + return 'C'; + } else if (score >= 80 && score <= 89) { + return 'B'; + } else if (score >= 90 && score <= 100) { + return 'A' + } + } + } let output = convertScoreToGrade(91); diff --git a/exercises/134-convertScoreToGradeWithPlus/app.js b/exercises/134-convertScoreToGradeWithPlus/app.js index 832778971..219cd315a 100644 --- a/exercises/134-convertScoreToGradeWithPlus/app.js +++ b/exercises/134-convertScoreToGradeWithPlus/app.js @@ -1,7 +1,30 @@ function convertScoreToGradeWithPlusAndMinus(score) { // your code here - -} - + if (score > 100 || score < 0) return 'INVALID SCORE'; + else { + if (score >= 90 && score <= 100) { + if (score >= 90 && score <= 92) return 'A-'; + if (score >= 98 && score <= 100) return 'A+'; + return 'A'; + } + if (score >= 80 && score <= 89) { + if (score >= 80 && score <= 82) return 'B-'; + if (score >= 88 && score <= 89) return 'B+'; + return 'B'; + } + if (score >= 70 && score <= 79) { + if (score >= 70 && score <= 72) return 'C-'; + if (score >= 78 && score <= 79) return 'C+'; + return 'C'; + } + if (score >= 60 && score <= 69) { + if (score >= 60 && score <= 62) return 'D-'; + if (score >= 68 && score <= 69) return 'D+'; + return 'D'; + } + if (score >= 0 && score <= 59) return 'F'; + } + } + let output = convertScoreToGradeWithPlusAndMinus(91); console.log(output); // --> 'A-' diff --git a/exercises/135-computeFactorialOfN/app.js b/exercises/135-computeFactorialOfN/app.js index 355f2cf34..88e1eae26 100644 --- a/exercises/135-computeFactorialOfN/app.js +++ b/exercises/135-computeFactorialOfN/app.js @@ -1,6 +1,11 @@ function computeFactorialOfN(n) { // your code here - + let total = 1 + for (let i = total; i <= n; i++) { + total *= i; + } + return total + } let output = computeFactorialOfN(4); diff --git a/exercises/136-sumDigits/app.js b/exercises/136-sumDigits/app.js index ae3503fab..963536ce8 100644 --- a/exercises/136-sumDigits/app.js +++ b/exercises/136-sumDigits/app.js @@ -1,7 +1,20 @@ function sumDigits(num) { // your code here - -} - -let output = sumDigits(-316); -console.log(output); // --> 4 + let numStr = num.toString(); + let sum = 0; + + for (let i = 0; i < numStr.length; i++) { + if (i === 0 && numStr[i] === "-") { + sum -= Number(numStr[i + 1]); + i++; + } else { + sum += Number(numStr[i]); + } + } + + return sum; + } + + let output = sumDigits(-316); + console.log(output); // --> 4 + \ No newline at end of file diff --git a/exercises/137-computeCompoundInterest/app.js b/exercises/137-computeCompoundInterest/app.js index 65bd4f8bc..91adf3c78 100644 --- a/exercises/137-computeCompoundInterest/app.js +++ b/exercises/137-computeCompoundInterest/app.js @@ -1,6 +1,7 @@ function computeCompoundInterest(principal, interestRate, compoundingFrequency, timeInYears) { // your code here - + let total = (principal * (Math.pow((1 + interestRate / compoundingFrequency),(compoundingFrequency * timeInYears)))) - principal; + return total; } let output = computeCompoundInterest(1500, .043, 4, 6); diff --git a/exercises/138-modulo/app.js b/exercises/138-modulo/app.js index 6b8d41e49..21ce977d8 100644 --- a/exercises/138-modulo/app.js +++ b/exercises/138-modulo/app.js @@ -1,5 +1,13 @@ function modulo(num1, num2) { // your code here + if(num1==0){ + return 0; + }else if(num2==0 || num1==NaN || num2==NaN){ + return NaN + } + let mod = num1 - num2 * Math.trunc(num1 / num2); + return mod === 0 ? 0 : (num1 < 0 && mod > 0) ? mod - Math.abs(num2) : mod; + } diff --git a/exercises/139-multiply/app.js b/exercises/139-multiply/app.js index ce9316306..c08506f2e 100644 --- a/exercises/139-multiply/app.js +++ b/exercises/139-multiply/app.js @@ -1,7 +1,20 @@ function multiply(num1, num2) { // your code here + let total=0; + for(let i=0;i 28 diff --git a/exercises/140-isOddWithoutModulo/app.js b/exercises/140-isOddWithoutModulo/app.js index 87086a67f..9d6b0530a 100644 --- a/exercises/140-isOddWithoutModulo/app.js +++ b/exercises/140-isOddWithoutModulo/app.js @@ -1,7 +1,7 @@ function isOddWithoutModulo(num) { // your code here - + return (num & 1) === 1; } -let output = isOddWithoutModulo(17); +let output = isOddWithoutModulo(2); console.log(output); // --> true diff --git a/exercises/141-isEvenWithoutModulo/app.js b/exercises/141-isEvenWithoutModulo/app.js index 97b25536a..4b0dc70d4 100644 --- a/exercises/141-isEvenWithoutModulo/app.js +++ b/exercises/141-isEvenWithoutModulo/app.js @@ -1,5 +1,6 @@ function isEvenWithoutModulo(num) { // your code here + return (num & 1) === 0; } diff --git a/exercises/142.1-ArrayToObject/app.js b/exercises/142.1-ArrayToObject/app.js index bde6dd105..f3e7e4c5f 100644 --- a/exercises/142.1-ArrayToObject/app.js +++ b/exercises/142.1-ArrayToObject/app.js @@ -1,5 +1,9 @@ function transformFirstAndLast(array) { // your code here + let obj={}; + obj[array.shift()] = array.pop(); + return obj + } diff --git a/exercises/142.2-ArrayToObject/app.js b/exercises/142.2-ArrayToObject/app.js index 3617152ab..fbedbc180 100644 --- a/exercises/142.2-ArrayToObject/app.js +++ b/exercises/142.2-ArrayToObject/app.js @@ -1,6 +1,11 @@ function fromListToObject(array) { // your code here - + let obj = {} + for (arr in array) { + obj[array[arr][0]] = array[arr][1]; + } + return obj; + } let output = fromListToObject([['make', 'Ford'], ['model', 'Mustang'], ['year', 1964]]) diff --git a/exercises/142.3-ArrayToObject/app.js b/exercises/142.3-ArrayToObject/app.js index fd435eeff..5fe87cc92 100644 --- a/exercises/142.3-ArrayToObject/app.js +++ b/exercises/142.3-ArrayToObject/app.js @@ -1,4 +1,13 @@ function transformEmployeeData(array) { // your code here + let result = []; + for (let x of array) { + let aux = {}; + for (let y of x) { + aux[y[0]] = y[1]; + } + result.push(aux); + } + return result; } diff --git a/exercises/143.1-ObjectToArray/app.js b/exercises/143.1-ObjectToArray/app.js index c3dd0ee84..daceab746 100644 --- a/exercises/143.1-ObjectToArray/app.js +++ b/exercises/143.1-ObjectToArray/app.js @@ -1,5 +1,6 @@ function getAllKeys(obj) { // your code here + return Object.keys(obj); } diff --git a/exercises/143.2-ObjectToArray/app.js b/exercises/143.2-ObjectToArray/app.js index 6bd6e18b0..0f56e5700 100644 --- a/exercises/143.2-ObjectToArray/app.js +++ b/exercises/143.2-ObjectToArray/app.js @@ -1,5 +1,6 @@ function listAllValues(obj) { // your code here + return Object.values(obj); } diff --git a/exercises/143.3-ObjectToArray/app.js b/exercises/143.3-ObjectToArray/app.js index dab51da1f..c48793e0e 100644 --- a/exercises/143.3-ObjectToArray/app.js +++ b/exercises/143.3-ObjectToArray/app.js @@ -1,5 +1,10 @@ function convertObjectToList(obj) { // your code here + let list=[]; + for(k in obj){ + list.push([k,obj[k]]); + } + return list; } diff --git a/exercises/144-getStringLength/app.js b/exercises/144-getStringLength/app.js index 11bc7ad77..1a0b60e0a 100644 --- a/exercises/144-getStringLength/app.js +++ b/exercises/144-getStringLength/app.js @@ -1,5 +1,10 @@ function getStringLength(string) { // your code here + let cont=0; + for(k in string){ + cont+=1; + } + return cont; } diff --git a/exercises/145-GreetCustomers/app.js b/exercises/145-GreetCustomers/app.js index 1d346e52f..920df1825 100644 --- a/exercises/145-GreetCustomers/app.js +++ b/exercises/145-GreetCustomers/app.js @@ -16,8 +16,16 @@ let customerData = { function greetCustomer(firstName) { let greeting = ''; // your code here - + if (!(customerData[firstName])) { + greeting = 'Welcome! Is this your first time?'; + } else { + if (customerData[firstName].visits == 1) { + greeting = "Welcome back, Joe! We're glad you liked us the first time!"; + } else if (customerData[firstName].visits > 1) { + greeting = "Welcome back, Carol! So glad to see you again!"; + } + } return greeting; } -console.log(greetCustomer('Joe')); // --> 'Welcome back, Joe! We're glad you liked us the first time!' +console.log(greetCustomer('Howard')); // --> 'Welcome back, Joe! We're glad you liked us the first time!' diff --git a/exercises/146-flipPairs/app.js b/exercises/146-flipPairs/app.js index dc55ff373..54a0a24ea 100644 --- a/exercises/146-flipPairs/app.js +++ b/exercises/146-flipPairs/app.js @@ -1,5 +1,6 @@ function flipPairs(input) { // your code here + return input.replace(/(.)(.)/g, '$2$1'); } diff --git a/exercises/147-flipEveryNChars/app.js b/exercises/147-flipEveryNChars/app.js index 71ef06464..a6dea4d30 100644 --- a/exercises/147-flipEveryNChars/app.js +++ b/exercises/147-flipEveryNChars/app.js @@ -1,8 +1,16 @@ function flipEveryNChars(input, n) { // your code here - -} - -let input = 'a short example'; -let output = flipEveryNChars(input, 5); -console.log(output); // --> ohs axe trelpma + let reges = `(.{${n}})`; + let parsed = new RegExp(reges); + + let result = input + .split(parsed) + .map((e) => e.split('').reverse().join('')) + .join(''); + return result; + } + + let input = 'a short example'; + let output = flipEveryNChars(input, 5); + console.log(output); // --> ohs axe trelpma + \ No newline at end of file diff --git a/exercises/148-detectOutlierValue/app.js b/exercises/148-detectOutlierValue/app.js index ec30628a5..f9ad18718 100644 --- a/exercises/148-detectOutlierValue/app.js +++ b/exercises/148-detectOutlierValue/app.js @@ -1,10 +1,26 @@ function detectOutlierValue(string) { // your code here - -} - -// Third number is odd, while the rest of the numbers are even -console.log(detectOutlierValue("2 4 7 8 10")); // --> 3 - -// Second number is even, while the rest of the numbers are odd -console.log(detectOutlierValue("1 10 1 1")) // --> 2 + let oddNumbers = 0; + let evenNumbers = 0; + let result = string.split(' '); + for (let x of result) { + if (Number.parseInt(x) % 2 == 0) evenNumbers += 1; + if (Number.parseInt(x) % 2 != 0) oddNumbers += 1; + } + if (evenNumbers > oddNumbers) { + for (let x = 0; x < result.length; x++) { + if (Number.parseInt(result[x]) % 2 != 0) return x + 1; + } + } else { + for (let x = 0; x < result.length; x++) { + if (Number.parseInt(result[x]) % 2 == 0) return x + 1; + } + } + } + + // Third number is odd, while the rest of the numbers are even + console.log(detectOutlierValue('2 4 7 8 10')); // --> 3 + + // Second number is even, while the rest of the numbers are odd + console.log(detectOutlierValue('1 10 1 1')); // --> 2 + \ No newline at end of file diff --git a/exercises/149-findPairForSum/app.js b/exercises/149-findPairForSum/app.js index 105611727..761479b7b 100644 --- a/exercises/149-findPairForSum/app.js +++ b/exercises/149-findPairForSum/app.js @@ -1,5 +1,12 @@ function findPairForSum(array, number) { // your code here + for(num in array){ + for(let i=0;i true - console.log(isRotated('hello world', 'omrel wp')); // --> false - + while (k--) { + let ch = q2[0] + q2.shift() + q2.push(ch) + if (JSON.stringify(q2) == JSON.stringify(q1)) + return true + } + + return false +} + +console.log(isRotated('hello world', 'orldhello w')); // --> true +console.log(isRotated('hello world', 'omrel wp')); // --> false + diff --git a/exercises/151-search/app.js b/exercises/151-search/app.js index 17e163aad..b8764a67c 100644 --- a/exercises/151-search/app.js +++ b/exercises/151-search/app.js @@ -1,7 +1,17 @@ function search(array, value) { // your code here - + let start = 0 + let end = array.length - 1; + while (start <= end) { + let mid = Math.floor((start + end) / 2); + if (array[mid] === value) return mid; + else if (array[mid] < value) + start = mid + 1; + else + end = mid - 1; + } + return null; } -let arr = [1, 3, 16, 22, 31, 33, 34] +let arr = [1, 3, 16, 22, 31, 33, 34]; console.log(search(arr, 31)); // --> 4 diff --git a/exercises/152-isogram/app.js b/exercises/152-isogram/app.js index 9e07e791c..fc1b8eeff 100644 --- a/exercises/152-isogram/app.js +++ b/exercises/152-isogram/app.js @@ -1,7 +1,17 @@ function isIsogram(text) { // your code here - + let lowerCaseText = text.toLowerCase() + + const chars = {}; + for (const char of lowerCaseText) { + chars[char] = (chars[char] || 0) + 1; + } + let result = Object.entries(chars) + .filter((char) => char[1] > 1) + .map((char) => char[0]); + if (result.length > 0) return false; + else return true; } -console.log(isIsogram("Camile")); // --> true -console.log(isIsogram("Camille")); // --> false +console.log(isIsogram('Camile')); // --> true +console.log(isIsogram('Camille')); // --> false diff --git a/exercises/153-phoneNumber/app.js b/exercises/153-phoneNumber/app.js index 2327bdc17..55ecce1cf 100644 --- a/exercises/153-phoneNumber/app.js +++ b/exercises/153-phoneNumber/app.js @@ -5,23 +5,23 @@ function PhoneNumberFormatter(numbers) { PhoneNumberFormatter.prototype.render = function() { let string = ''; // your code here - + string = this.parenthesize(this.getAreaCode()) + " " + this.getExchangeCode() + "-" + this.getLineNumber(); return string; }; PhoneNumberFormatter.prototype.getAreaCode = function() { // your code here - + return this.slice(0,3); }; PhoneNumberFormatter.prototype.getExchangeCode = function() { // your code here - + return this.slice(3,6); }; PhoneNumberFormatter.prototype.getLineNumber = function() { // your code here - + return this.slice(6,10); }; PhoneNumberFormatter.prototype.parenthesize = function(string) { diff --git a/exercises/154-longestPalindrome/app.js b/exercises/154-longestPalindrome/app.js index e76c1c24a..35e2b220b 100644 --- a/exercises/154-longestPalindrome/app.js +++ b/exercises/154-longestPalindrome/app.js @@ -1,16 +1,26 @@ function findLongestPalindrome(sentence) { // your code here - + let longestPalindrome = ''; + + for (let i = 0; i < sentence.length; i++) { + let word = ''; + for (let j = i; j < sentence.length; j++) { + word += sentence[j]; + if (isPalindrome(word) && word.length > longestPalindrome.length) longestPalindrome = word + } + } + + return longestPalindrome } function reverseString(string) { // your code here - + return string.split('').reverse().join(''); } function isPalindrome(word) { // your code here - + return word.length > 1 && word.toLowerCase() === reverseString(word.toLowerCase()); } let output = findLongestPalindrome("My dad is a racecar athlete"); diff --git a/exercises/155.1-FashionInventory-A/app.js b/exercises/155.1-FashionInventory-A/app.js index 5fe53d974..91cb94c51 100644 --- a/exercises/155.1-FashionInventory-A/app.js +++ b/exercises/155.1-FashionInventory-A/app.js @@ -18,10 +18,16 @@ let currentInventory = [ ]; function renderInventory(inventory) { - // your code here - // hint: before you just dive into coding... - // it's a good idea to sketch out a skeleton like you've been seeing earlier in this module... - + // your code here + // hint: before you just dive into coding... + // it's a good idea to sketch out a skeleton like you've been seeing earlier in this module... + let aux = []; + inventory.map((e) => { + e.shoes.map((x) => { + aux.push([e.name, x.name, x.price]); + }); + }); + return aux; } -console.log(renderInventory(currentInventory)) +console.log(renderInventory(currentInventory)); diff --git a/exercises/155.2-FashionInventory-B/app.js b/exercises/155.2-FashionInventory-B/app.js index c081b0174..aaffb2e8d 100644 --- a/exercises/155.2-FashionInventory-B/app.js +++ b/exercises/155.2-FashionInventory-B/app.js @@ -19,6 +19,17 @@ let currentInventory = [ function renderAverageCostPerDesigner(inventory) { // your code here + let finalList=[] + let average = 0; + for(let i=0;i { + item.shoes.map((item2, index) => { + if (item2.name.includes("black")) newListOfBlack.push([item.name, item2.name, item2.price]) + }) +}) +return newListOfBlack; } console.log(renderInventory(currentInventory)); diff --git a/exercises/155.4-FashionInventory-D/app.js b/exercises/155.4-FashionInventory-D/app.js index 22196ba8c..dffeaa6c3 100644 --- a/exercises/155.4-FashionInventory-D/app.js +++ b/exercises/155.4-FashionInventory-D/app.js @@ -18,8 +18,20 @@ let currentInventory = [ ]; function getLaceNameDataForShoes(inventory) { - // your code here - + // your code here + let aux = []; + inventory.map((e) => { + e.shoes.map((x) => { + let splited = x.name.split(' '); + let counting = 0; + splited.map((s) => { + if (s.startsWith('lace')) + aux.push({ nameWords: splited, targetWordIndex: counting }); + else counting++; + }); + }); + }); + return aux; } console.log(getLaceNameDataForShoes(currentInventory)); From d84f7b0915d6fec0b821604f63a1fcf0c0549334 Mon Sep 17 00:00:00 2001 From: DevWilfredo Date: Mon, 31 Mar 2025 17:15:01 +0000 Subject: [PATCH 2/2] Initial commit