diff --git a/exercises/001-isOldEnoughToDrink/app.js b/exercises/001-isOldEnoughToDrink/app.js index c4d3bab4d..2d5999de8 100644 --- a/exercises/001-isOldEnoughToDrink/app.js +++ b/exercises/001-isOldEnoughToDrink/app.js @@ -1,4 +1,16 @@ function isOldEnoughToDrink(age) { // your code here + let legal_age = false; + if (age >= 21) { + legal_age = true; + } + + else { + legal_age = false + } + + return legal_age } + +isOldEnoughToDrink(15) \ No newline at end of file diff --git a/exercises/002-isOldEnoughToDrive/app.js b/exercises/002-isOldEnoughToDrive/app.js index 0ab7348dd..583604d1a 100644 --- a/exercises/002-isOldEnoughToDrive/app.js +++ b/exercises/002-isOldEnoughToDrive/app.js @@ -1,4 +1,15 @@ function isOldEnoughToDrive(age) { // your code here - + let legal_age = false; + + if (age >= 16){ + legal_age = true; + } + else { + legal_age = false; + } + + return legal_age } + +isOldEnoughToDrive(12) diff --git a/exercises/003-isOldEnoughToVote/app.js b/exercises/003-isOldEnoughToVote/app.js index 63c4efb41..35c9f01d2 100644 --- a/exercises/003-isOldEnoughToVote/app.js +++ b/exercises/003-isOldEnoughToVote/app.js @@ -1,4 +1,13 @@ function isOldEnoughToVote(age) { // your code here - + let legal_age = false; + + if( age >= 18) { + legal_age = true; + } + else { + legal_age = false; + } + return legal_age } + isOldEnoughToVote(12) \ No newline at end of file diff --git a/exercises/004-isOldEnoughToDrinkAndDrive/app.js b/exercises/004-isOldEnoughToDrinkAndDrive/app.js index c8c52473a..85aa5faca 100644 --- a/exercises/004-isOldEnoughToDrinkAndDrive/app.js +++ b/exercises/004-isOldEnoughToDrinkAndDrive/app.js @@ -1,4 +1,28 @@ function isOldEnoughToDrinkAndDrive(age) { // your code here - + let drink_age = false; + let drive_age = false; + + let legal_age = false; + + if (age >= 21) { + drink_age = true; + } else { + drink_age = false; + } + + if (age >= 16) { + drive_age = true; + } else { + drive_age = false + } + + if (drink_age && drive_age) { + legal_age = false; + } else { + legal_age = false; + } + return legal_age } + +isOldEnoughToDrinkAndDrive \ No newline at end of file diff --git a/exercises/005-checkAge/app.js b/exercises/005-checkAge/app.js index 0ff57081e..cf78bbabe 100644 --- a/exercises/005-checkAge/app.js +++ b/exercises/005-checkAge/app.js @@ -1,4 +1,15 @@ function checkAge(name, age) { // your code here + let message = ``; + if(age >= 21){ + message = `Welcome, ${name}!` + } else { + message = `Go home, ${name}!` + } + + return message } + + +checkAge("Florencia", 23) diff --git a/exercises/006-getFullName/app.js b/exercises/006-getFullName/app.js index e8d8b83a8..c0f93976c 100644 --- a/exercises/006-getFullName/app.js +++ b/exercises/006-getFullName/app.js @@ -1,4 +1,10 @@ function getFullName(firstName, lastName) { // your code here - + let full_name = ""; + + full_name = firstName + " " + lastName; + + return full_name } + +getFullName("james", "bond") diff --git a/exercises/007-getLengthOfWord/app.js b/exercises/007-getLengthOfWord/app.js index 8d04d4f58..8107ee75f 100644 --- a/exercises/007-getLengthOfWord/app.js +++ b/exercises/007-getLengthOfWord/app.js @@ -1,4 +1,10 @@ function getLengthOfWord(word) { // your code here - + let word_length = 0; + + word_length = word.length + + return word_length + } +getLengthOfWord("magnifico") \ No newline at end of file diff --git a/exercises/008-getLengthOfTwoWords/app.js b/exercises/008-getLengthOfTwoWords/app.js index 032c8cff4..340090955 100644 --- a/exercises/008-getLengthOfTwoWords/app.js +++ b/exercises/008-getLengthOfTwoWords/app.js @@ -1,4 +1,11 @@ function getLengthOfTwoWords(word1, word2) { // your code here - + let palabra_1 = word1.length; + let palabra_2 = word2.length; + + let full_length = palabra_1 + palabra_2 + + return full_length } + +getLengthOfTwoWords("ana", "carolina") diff --git a/exercises/009-getLengthOfThreeWords/app.js b/exercises/009-getLengthOfThreeWords/app.js index 9049a6d5d..c9d1e1beb 100644 --- a/exercises/009-getLengthOfThreeWords/app.js +++ b/exercises/009-getLengthOfThreeWords/app.js @@ -1,6 +1,8 @@ function getLengthOfThreeWords(word1, word2, word3) { // your code here - + let palabras = word1.length + word2.length + word3.length + + return palabras } let output = getLengthOfThreeWords('some', 'other', 'words'); diff --git a/exercises/010-isSameLength/app.js b/exercises/010-isSameLength/app.js index 6ebc804ae..e86e375a6 100644 --- a/exercises/010-isSameLength/app.js +++ b/exercises/010-isSameLength/app.js @@ -1 +1,15 @@ -// Write your function here \ No newline at end of file +// Write your function here +function isSameLength(word1, word2){ + + let iguales = false; + + if(word1.length === word2.length){ + iguales = true; + } else { + iguales = false; + } + + return iguales +} + +isSameLength("hola", "chau") \ No newline at end of file diff --git a/exercises/011-isGreaterThanTen/app.js b/exercises/011-isGreaterThanTen/app.js index b60c49b11..da79f597d 100644 --- a/exercises/011-isGreaterThanTen/app.js +++ b/exercises/011-isGreaterThanTen/app.js @@ -1,4 +1,14 @@ function isGreaterThanTen(num) { // your code here + let es_mayor = false; + if(num > 10) { + es_mayor = true; + } else { + es_mayor = false; + } + + return es_mayor } + +isGreaterThanTen(18) diff --git a/exercises/012-isLessThanThirty/app.js b/exercises/012-isLessThanThirty/app.js index a9612b873..7bc0d4d3f 100644 --- a/exercises/012-isLessThanThirty/app.js +++ b/exercises/012-isLessThanThirty/app.js @@ -1,4 +1,14 @@ function isLessThan30(num) { // your code here - + let menor_30 = false; + + if(num < 30) { + menor_30 = true + } else { + menor_30 = false; + } + + return menor_30 } + +isLessThan30(25) \ No newline at end of file diff --git a/exercises/013-equalsTen/app.js b/exercises/013-equalsTen/app.js index 0d5c28e62..b69be6e25 100644 --- a/exercises/013-equalsTen/app.js +++ b/exercises/013-equalsTen/app.js @@ -1,4 +1,15 @@ function equalsTen(num) { // your code here - + let igual = false; + + if(num === 10) { + igual = true + } else { + igual = false + } + + + return igual } + +equalsTen(10) diff --git a/exercises/014-isLessThan/app.js b/exercises/014-isLessThan/app.js index d7572d4ad..929f7cc38 100644 --- a/exercises/014-isLessThan/app.js +++ b/exercises/014-isLessThan/app.js @@ -1,3 +1,14 @@ function isLessThan(num1, num2) { // your code here + let es_menor_que = false; + + if(num2 < num1) { + es_menor_que = true; + } else { + es_menor_que = false; + } + + return es_menor_que } + +isLessThan(9, 4) \ No newline at end of file diff --git a/exercises/015-isGreaterThan/app.js b/exercises/015-isGreaterThan/app.js index 83c54fd95..7246f0129 100644 --- a/exercises/015-isGreaterThan/app.js +++ b/exercises/015-isGreaterThan/app.js @@ -1,4 +1,14 @@ function isGreaterThan(num1, num2) { // your code here - + let es_mayor = false; + + if(num2 > num1){ + es_mayor = true; + + } else { + es_mayor = false; + } + return es_mayor } + +isGreaterThan(11, 10); diff --git a/exercises/016-isEqualTo/app.js b/exercises/016-isEqualTo/app.js index 6ebc804ae..b970d784f 100644 --- a/exercises/016-isEqualTo/app.js +++ b/exercises/016-isEqualTo/app.js @@ -1 +1,14 @@ -// Write your function here \ No newline at end of file +// Write your function here +function isEqualTo(num1, num2) { + let son_igules = false; + + if(num2 === num1) { + son_igules = true; + } else { + son_igules = false; + } + + return son_igules +} + +isEqualTo(11, 10) \ No newline at end of file diff --git a/exercises/017-isEven/app.js b/exercises/017-isEven/app.js index 6ebc804ae..19bc7a239 100644 --- a/exercises/017-isEven/app.js +++ b/exercises/017-isEven/app.js @@ -1 +1,15 @@ -// Write your function here \ No newline at end of file +// Write your function here +function isEven(numero) { + + let es_par = false; + + if( numero % 2 === 0 ){ + es_par = true; + } else { + es_par = false; + } + + return es_par +} + +isEven(11) \ No newline at end of file diff --git a/exercises/018-isOdd/app.js b/exercises/018-isOdd/app.js index 6ebc804ae..9382b1bf1 100644 --- a/exercises/018-isOdd/app.js +++ b/exercises/018-isOdd/app.js @@ -1 +1,13 @@ -// Write your function here \ No newline at end of file +// Write your function here +function isOdd(num) { + let impar = false; + if(num % 2 === 0) { + impar = false; + } else { + impar = true; + } + + return impar +} + +isOdd(9) \ No newline at end of file diff --git a/exercises/019-areBothOdd/app.js b/exercises/019-areBothOdd/app.js index 3e2df3368..046fa1a4b 100644 --- a/exercises/019-areBothOdd/app.js +++ b/exercises/019-areBothOdd/app.js @@ -1 +1,20 @@ // Write your function here +function areBothOdd(num1, num2) { + + let pares = false; + + if(num1 % 2 === 0 && num2 % 2 === 0) { + pares = false + } + + if(num1 % 2 === 0 || num2 % 2 === 0) { + pares = false + } + else { + pares = true + } + + return pares +} + +areBothOdd(1, 3) \ No newline at end of file diff --git a/exercises/020-isEitherEven/app.js b/exercises/020-isEitherEven/app.js index 6ebc804ae..866c92023 100644 --- a/exercises/020-isEitherEven/app.js +++ b/exercises/020-isEitherEven/app.js @@ -1 +1,15 @@ -// Write your function here \ No newline at end of file +// Write your function here +function isEitherEven (num1, num2) { + + let pares = false; + + if (num1 % 2 === 0 || num2 % 2 === 0 ) { + pares = true; + } else { + pares = false; + } + + return pares +} + +isEitherEven(1, 4) \ No newline at end of file diff --git a/exercises/021-isOddLength/app.js b/exercises/021-isOddLength/app.js index 3e2df3368..d8f7a999e 100644 --- a/exercises/021-isOddLength/app.js +++ b/exercises/021-isOddLength/app.js @@ -1 +1,15 @@ // Write your function here +function isOddLength(palabra) { + + let es_inpar = false; + + if( palabra.length % 2 === 0 ) { + es_inpar = false; + } else { + es_inpar = true; + } + + return es_inpar +} + +isOddLength('special') \ No newline at end of file diff --git a/exercises/022-isEvenLength/app.js b/exercises/022-isEvenLength/app.js index 6ebc804ae..66413b3df 100644 --- a/exercises/022-isEvenLength/app.js +++ b/exercises/022-isEvenLength/app.js @@ -1 +1,16 @@ -// Write your function here \ No newline at end of file +// Write your function here +function isEvenLength(word){ + + let par = false; + + if( word.length % 2 === 0) { + par = true; + } else { + par = false; + } + + return par; + +} + +isEvenLength('wow'); \ No newline at end of file diff --git a/exercises/023-computeAverageLengthOfWords/app.js b/exercises/023-computeAverageLengthOfWords/app.js index 6ebc804ae..55c9550d7 100644 --- a/exercises/023-computeAverageLengthOfWords/app.js +++ b/exercises/023-computeAverageLengthOfWords/app.js @@ -1 +1,11 @@ -// Write your function here \ No newline at end of file +// Write your function here +function computeAverageLengthOfWords(word1, word2){ + + let promedio = (word1.length + word2.length) / 2; + + + + return promedio; +} + +computeAverageLengthOfWords('code', 'programs') \ No newline at end of file diff --git a/exercises/024-isEvenAndGreaterThanTen/app.js b/exercises/024-isEvenAndGreaterThanTen/app.js index 6ebc804ae..c4dd583cf 100644 --- a/exercises/024-isEvenAndGreaterThanTen/app.js +++ b/exercises/024-isEvenAndGreaterThanTen/app.js @@ -1 +1,16 @@ -// Write your function here \ No newline at end of file +// Write your function here +function isEvenAndGreaterThanTen(num) { + + let resultado = false; + + if(num > 10 && num % 2 === 0){ + resultado = true; + } + else{ + resultado = false; + } + + return resultado +} + +isEvenAndGreaterThanTen(13) \ No newline at end of file diff --git a/exercises/025-average/app.js b/exercises/025-average/app.js index 6ebc804ae..d5038f13a 100644 --- a/exercises/025-average/app.js +++ b/exercises/025-average/app.js @@ -1 +1,8 @@ -// Write your function here \ No newline at end of file +function average(num1, num2){ + + let resultado = (num1 + num2) / 2; + + return resultado +} + + average(4, 6) \ No newline at end of file diff --git a/exercises/026-computeAreaOfATriangle/app.js b/exercises/026-computeAreaOfATriangle/app.js index 3e2df3368..1305c4e92 100644 --- a/exercises/026-computeAreaOfATriangle/app.js +++ b/exercises/026-computeAreaOfATriangle/app.js @@ -1 +1,9 @@ // Write your function here +function computeAreaOfATriangle(base, heigth) { + + let area = (base * heigth) /2 + + return area +} + +computeAreaOfATriangle(4, 6) \ No newline at end of file diff --git a/exercises/027-cube/app.js b/exercises/027-cube/app.js index 6ebc804ae..3ccc29c9b 100644 --- a/exercises/027-cube/app.js +++ b/exercises/027-cube/app.js @@ -1 +1,8 @@ -// Write your function here \ No newline at end of file +// Write your function here +function cube(num) { + + let res = num ** 3 + return res +} + +cube(3) \ No newline at end of file diff --git a/exercises/028-square/app.js b/exercises/028-square/app.js index 3e2df3368..91e96c505 100644 --- a/exercises/028-square/app.js +++ b/exercises/028-square/app.js @@ -1 +1,7 @@ // Write your function here +function square(n) { + let subo = n**2 + return subo +} + +square(5) \ No newline at end of file diff --git a/exercises/029-getProperty/app.js b/exercises/029-getProperty/app.js index c83e6b544..d68bc034a 100644 --- a/exercises/029-getProperty/app.js +++ b/exercises/029-getProperty/app.js @@ -1,4 +1,13 @@ function getProperty(obj, key) { - // your code here - + // your code here+ + let variable = obj[key]; + + return variable; } + +let car = { + model: 'Toyota' + }; + + + getProperty(car, "model") \ No newline at end of file diff --git a/exercises/030-addProperty/app.js b/exercises/030-addProperty/app.js index e6c3fa031..4a8929bf4 100644 --- a/exercises/030-addProperty/app.js +++ b/exercises/030-addProperty/app.js @@ -1,4 +1,10 @@ function addProperty(obj, key) { // your code here - + obj[key] = true; + + return obj; } + +let car = {}; + +addProperty(car, "electrico") \ No newline at end of file diff --git a/exercises/031-removeProperty/app.js b/exercises/031-removeProperty/app.js index 56edcf7c5..edf435edf 100644 --- a/exercises/031-removeProperty/app.js +++ b/exercises/031-removeProperty/app.js @@ -1,4 +1,11 @@ function removeProperty(obj, key) { // your code here - + return delete obj[key] } + +let obj = { + name: 'Sam', + age: 20 +} + +removeProperty(obj, "name") \ No newline at end of file diff --git a/exercises/032-addFullNameProperty/app.js b/exercises/032-addFullNameProperty/app.js index db6651bc1..034f4da6f 100644 --- a/exercises/032-addFullNameProperty/app.js +++ b/exercises/032-addFullNameProperty/app.js @@ -1,4 +1,13 @@ function addFullNameProperty(obj) { // Add your code after this line - -} \ No newline at end of file + obj.fullName = obj.firstName + " " + obj.lastName + + return obj +} + +let person = { + firstName: 'Jade', + lastName: 'Smith' +} + +addFullNameProperty(person) \ No newline at end of file diff --git a/exercises/033-addObjectProperty/app.js b/exercises/033-addObjectProperty/app.js index 7f59b8c20..4e09216ca 100644 --- a/exercises/033-addObjectProperty/app.js +++ b/exercises/033-addObjectProperty/app.js @@ -1,4 +1,17 @@ function addObjectProperty(obj1, key, obj2) { // Add your code after this line + obj1[key] = obj2 -} \ No newline at end of file + return obj1 +} + +let person1 = { + name: 'Joe Blow', + role: 'schlub' +}; +let person2 = { + name: 'Mr. Burns', + role: 'supervisor' +}; + +addObjectProperty(person1, "boss", person2) \ No newline at end of file diff --git a/exercises/034-isPersonOldEnoughToDrive/app.js b/exercises/034-isPersonOldEnoughToDrive/app.js index a319c0d29..b7d93205e 100644 --- a/exercises/034-isPersonOldEnoughToDrive/app.js +++ b/exercises/034-isPersonOldEnoughToDrive/app.js @@ -1,4 +1,18 @@ function isPersonOldEnoughToDrive(person) { // Add your code after this line + let can_drive = false; + + if (person.age >= 16) { + can_drive = true; + } else { + can_drive = false; + } -} \ No newline at end of file + return can_drive +} + +let miguel = { + age: 16 +}; + +isPersonOldEnoughToDrive(miguel) \ No newline at end of file diff --git a/exercises/035-isPersonOldEnoughToVote/app.js b/exercises/035-isPersonOldEnoughToVote/app.js index 4f1c12a60..1cc571e95 100644 --- a/exercises/035-isPersonOldEnoughToVote/app.js +++ b/exercises/035-isPersonOldEnoughToVote/app.js @@ -1,4 +1,18 @@ function isPersonOldEnoughToVote(person) { // Add your code after this line - -} \ No newline at end of file + let can_vote = false; + + if (person.age >= 18){ + can_vote = true; + } else { + can_vote = false + } + + return can_vote +} + +let obj = { + age: 19 +}; + +isPersonOldEnoughToVote(obj) \ No newline at end of file diff --git a/exercises/036-isPersonOldEnoughToDrink/app.js b/exercises/036-isPersonOldEnoughToDrink/app.js index 09259549b..5334848dc 100644 --- a/exercises/036-isPersonOldEnoughToDrink/app.js +++ b/exercises/036-isPersonOldEnoughToDrink/app.js @@ -1,4 +1,17 @@ function isPersonOldEnoughToDrink(person) { // Add your code after this line - -} \ No newline at end of file + let can_drink = false; + + if (person.age >= 21) { + can_drink = true + } else { + can_drink = false + } + return can_drink +} + +let obj = { + age: 16 +}; + +isPersonOldEnoughToDrink(obj) \ No newline at end of file diff --git a/exercises/037-addArrayProperty/app.js b/exercises/037-addArrayProperty/app.js index 447c67dd7..cb301e1be 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 - -} \ No newline at end of file + obj[key] = arr; + + return myObj +} + +let myObj = {}; + +let myArray = [1, 3]; + +addArrayProperty(myObj, 'myProperty', myArray); \ No newline at end of file diff --git a/exercises/038-computeAreaOfARectangle/app.js b/exercises/038-computeAreaOfARectangle/app.js index 571189580..3b0f80566 100644 --- a/exercises/038-computeAreaOfARectangle/app.js +++ b/exercises/038-computeAreaOfARectangle/app.js @@ -1,6 +1,8 @@ function computeAreaOfARectangle(length, width) { // your code here + let area = length * width; + return area; } let output = computeAreaOfARectangle(10, 18); diff --git a/exercises/039-computePerimeterOfARectangle/app.js b/exercises/039-computePerimeterOfARectangle/app.js index 7e1097b42..5fe0a0cef 100644 --- a/exercises/039-computePerimeterOfARectangle/app.js +++ b/exercises/039-computePerimeterOfARectangle/app.js @@ -1,5 +1,8 @@ function computePerimeterOfARectangle(length, width) { // your code here + let perimetro = length * 2 + width * 2 + + return perimetro } let output = computePerimeterOfARectangle(5, 2); diff --git a/exercises/040-computePerimeterOfATriangle/app.js b/exercises/040-computePerimeterOfATriangle/app.js index 82e6eb746..60008a4c6 100644 --- a/exercises/040-computePerimeterOfATriangle/app.js +++ b/exercises/040-computePerimeterOfATriangle/app.js @@ -1,4 +1,8 @@ function computePerimeterOfATriangle(side1, side2, side3) { + + let perimetro = side1 + side2 + side3; + + return perimetro // your code here } diff --git a/exercises/041-computeTripledAreaOfARectangle/app.js b/exercises/041-computeTripledAreaOfARectangle/app.js index ce5e98336..1ddb03949 100644 --- a/exercises/041-computeTripledAreaOfARectangle/app.js +++ b/exercises/041-computeTripledAreaOfARectangle/app.js @@ -1,5 +1,8 @@ function computeTripledAreaOfARectangle(length, width) { // your code here + let area = ( length * width) * 3; + + return area } diff --git a/exercises/042-computePerimeterOfACircle/app.js b/exercises/042-computePerimeterOfACircle/app.js index 2bfad5f97..9710111a2 100644 --- a/exercises/042-computePerimeterOfACircle/app.js +++ b/exercises/042-computePerimeterOfACircle/app.js @@ -1,6 +1,8 @@ function computePerimeterOfACircle(radius) { // your code here + let perimetro = 2 * Math.PI * radius + return perimetro } let output = computePerimeterOfACircle(4); diff --git a/exercises/043-computeAreaOfACircle/app.js b/exercises/043-computeAreaOfACircle/app.js index a1931f81b..26ec97397 100644 --- a/exercises/043-computeAreaOfACircle/app.js +++ b/exercises/043-computeAreaOfACircle/app.js @@ -1,5 +1,8 @@ function computeAreaOfACircle(radius) { // your code here + let area = Math.PI * (radius ** 2) + + return area } let output = computeAreaOfACircle(4); diff --git a/exercises/044-computePower/app.js b/exercises/044-computePower/app.js index ceb56e0f3..5dcd6f2a1 100644 --- a/exercises/044-computePower/app.js +++ b/exercises/044-computePower/app.js @@ -1,5 +1,8 @@ function computePower(num, exponent) { // your code here + let power = num ** exponent + + return power } let output = computePower(2, 3); diff --git a/exercises/045-computeSquareRoot/app.js b/exercises/045-computeSquareRoot/app.js index 2145a7bee..36c772716 100644 --- a/exercises/045-computeSquareRoot/app.js +++ b/exercises/045-computeSquareRoot/app.js @@ -1,5 +1,8 @@ function computeSquareRoot(num) { // your code here + let raiz = Math.sqrt(num) + + return raiz } let output = computeSquareRoot(9); diff --git a/exercises/046-doubleSquareRootOf/app.js b/exercises/046-doubleSquareRootOf/app.js index 75cc74300..c9ab2508c 100644 --- a/exercises/046-doubleSquareRootOf/app.js +++ b/exercises/046-doubleSquareRootOf/app.js @@ -1,6 +1,7 @@ function doubleSquareRootOf(num) { // your code here - + let root = (Math.sqrt(num)) * 2 + return root } let output = doubleSquareRootOf(121); diff --git a/exercises/047-isEitherEvenOrAreBoth7/app.js b/exercises/047-isEitherEvenOrAreBoth7/app.js index c72dd1b3d..ce7256ea4 100644 --- a/exercises/047-isEitherEvenOrAreBoth7/app.js +++ b/exercises/047-isEitherEvenOrAreBoth7/app.js @@ -1,4 +1,20 @@ function isEitherEvenOrAreBoth7(num1, num2) { // your code here - + let resultado = false + + if(num1 === 7 && num2 === 7) { + resultado = true + } + else if (num1 % 2 === 0 || num2 % 2 === 0) { + resultado = true + } + else { + resultado = false + } + + return resultado } + + +let output = isEitherEvenOrAreBoth7(3, 7); +console.log(output); diff --git a/exercises/048-isEitherEvenAndLessThan9/app.js b/exercises/048-isEitherEvenAndLessThan9/app.js index 85320e272..c552fd53e 100644 --- a/exercises/048-isEitherEvenAndLessThan9/app.js +++ b/exercises/048-isEitherEvenAndLessThan9/app.js @@ -1,6 +1,14 @@ function isEitherEvenAndLessThan9(num1, num2) { // your code here + let result = false; + if(num1 < 9 && num2 < 9){ + result = true + } else { + result = false + } + + return result } let output = isEitherEvenAndLessThan9(2, 4); diff --git a/exercises/049-computeAverageOfNumbers/app.js b/exercises/049-computeAverageOfNumbers/app.js index 3e2df3368..6c4fab395 100644 --- a/exercises/049-computeAverageOfNumbers/app.js +++ b/exercises/049-computeAverageOfNumbers/app.js @@ -1 +1,22 @@ // Write your function here +function computeAverageOfNumbers(anArray){ + + if(anArray.length === 0 ){ + return 0; + } + + let suma = 0; + for(let i=0; i < anArray.length; i++){ + suma += anArray[i]; + } + + let average = suma / anArray.length + + return average +} + + +let input = [1, 2, 3, 4, 5]; + +let output = computeAverageOfNumbers(input); +console.log(output); \ No newline at end of file diff --git a/exercises/050-getNthElement/app.js b/exercises/050-getNthElement/app.js index 0c61fb9b3..c08476e5d 100644 --- a/exercises/050-getNthElement/app.js +++ b/exercises/050-getNthElement/app.js @@ -1,4 +1,8 @@ function getNthElement(array, n) { // Add your code after this line - + let resultado = array[n] + return resultado } + +let output = getNthElement([1, 3, 5], 1); +console.log(output) \ No newline at end of file diff --git a/exercises/051-getFirstElement/app.js b/exercises/051-getFirstElement/app.js index 2d285a8ba..48c9363eb 100644 --- a/exercises/051-getFirstElement/app.js +++ b/exercises/051-getFirstElement/app.js @@ -1,6 +1,8 @@ function getFirstElement(array) { // Add your code after this line + let first = array[0] + return first } let output = getFirstElement([1, 2, 3, 4, 5]); diff --git a/exercises/052-getLastElement/app.js b/exercises/052-getLastElement/app.js index de124d218..c41581513 100644 --- a/exercises/052-getLastElement/app.js +++ b/exercises/052-getLastElement/app.js @@ -1,4 +1,8 @@ function getLastElement(array) { // Add your code after this line - + let last = array[array.length - 1] + + return last } +let output = getLastElement([1, 2, 3, 4]); +console.log(output); diff --git a/exercises/053-addToFront/app.js b/exercises/053-addToFront/app.js index b7fcd6959..d5f5217eb 100644 --- a/exercises/053-addToFront/app.js +++ b/exercises/053-addToFront/app.js @@ -1,6 +1,8 @@ function addToFront(arr, element) { // your code here - + arr.unshift(element) + + return arr } let output = addToFront([1, 2], 3); diff --git a/exercises/054-addToBack/app.js b/exercises/054-addToBack/app.js index ac69fcce3..4e99b4804 100644 --- a/exercises/054-addToBack/app.js +++ b/exercises/054-addToBack/app.js @@ -1,7 +1,8 @@ function addToBack(arr, element) { // your code here - -} + arr.push(element) + return arr +} let output = addToBack([1, 2], 3); console.log(output); // -> [1, 2, 3] diff --git a/exercises/055-joinArrays/app.js b/exercises/055-joinArrays/app.js index 3e1b15be8..490b3c62f 100644 --- a/exercises/055-joinArrays/app.js +++ b/exercises/055-joinArrays/app.js @@ -1,6 +1,6 @@ function joinArrays(arr1, arr2) { // your code here - + return arr1.concat(arr2) } let output = joinArrays([1, 2], [3, 4]); diff --git a/exercises/056-getElementsAfter/app.js b/exercises/056-getElementsAfter/app.js index c7020f6fa..33033c9ef 100644 --- a/exercises/056-getElementsAfter/app.js +++ b/exercises/056-getElementsAfter/app.js @@ -1,6 +1,6 @@ function getElementsAfter(array, n) { // your code here - + return array.slice(n + 1 ) } let output = getElementsAfter(['a', 'b', 'c', 'd', 'e'], 2); diff --git a/exercises/057-getElementsUpTo/app.js b/exercises/057-getElementsUpTo/app.js index 4387f3611..ddd0ec67c 100644 --- a/exercises/057-getElementsUpTo/app.js +++ b/exercises/057-getElementsUpTo/app.js @@ -1,6 +1,6 @@ function getElementsUpTo(array, n) { // your code here - + return array.slice(0, n) } let output = getElementsUpTo(['a', 'b', 'c', 'd', 'e'], 3) diff --git a/exercises/058-removeFromFront/app.js b/exercises/058-removeFromFront/app.js index 409ef58b0..d9f9a991b 100644 --- a/exercises/058-removeFromFront/app.js +++ b/exercises/058-removeFromFront/app.js @@ -1,6 +1,8 @@ function removeFromFront(arr) { // your code here - + arr.shift() + + return arr } let output = removeFromFront([1, 2, 3]); diff --git a/exercises/059-removeFromBack/app.js b/exercises/059-removeFromBack/app.js index 777da4683..c7a87f243 100644 --- a/exercises/059-removeFromBack/app.js +++ b/exercises/059-removeFromBack/app.js @@ -1,6 +1,7 @@ function removeFromBack(arr) { // your code here - + arr.pop() + return arr } let output = removeFromBack([1, 2, 3]); diff --git a/exercises/060-removeFromFrontOfNew/app.js b/exercises/060-removeFromFrontOfNew/app.js index 893cf2a18..bc6089b3c 100644 --- a/exercises/060-removeFromFrontOfNew/app.js +++ b/exercises/060-removeFromFrontOfNew/app.js @@ -1,6 +1,6 @@ function removeFromFrontOfNew(arr) { // your code here - + return arr.slice(1) } let arr = [1, 2, 3]; diff --git a/exercises/061-removeFromBackOfNew/app.js b/exercises/061-removeFromBackOfNew/app.js index df89dcd53..af4a28d57 100644 --- a/exercises/061-removeFromBackOfNew/app.js +++ b/exercises/061-removeFromBackOfNew/app.js @@ -1,6 +1,6 @@ function removeFromBackOfNew(arr) { // your code here - + return arr.slice(0,-1) } let arr = [1, 2, 3]; diff --git a/exercises/062-countCharacter/app.js b/exercises/062-countCharacter/app.js index 29557e7c7..4caf847dd 100644 --- a/exercises/062-countCharacter/app.js +++ b/exercises/062-countCharacter/app.js @@ -1,7 +1,15 @@ function countCharacter(str, char) { // your code here - -} + let cantidad = 0; + + for( let i = 0; i < str.length; i++){ + if (str[i] === char){ + cantidad += 1; + } + } + + return cantidad + } let output = countCharacter('I am a hacker', 'a'); console.log(output); // --> 3 diff --git a/exercises/063-getAllLetters/app.js b/exercises/063-getAllLetters/app.js index 7f5dc731b..a7db848cf 100644 --- a/exercises/063-getAllLetters/app.js +++ b/exercises/063-getAllLetters/app.js @@ -1,6 +1,13 @@ function getAllLetters(str) { // your code here - + let letras = []; + + for(let i in str){ + letras.push(str[i]) + + } + + return letras } let output = getAllLetters('Radagast'); diff --git a/exercises/064-getAllWords/app.js b/exercises/064-getAllWords/app.js index 53ccd4666..711d0a26a 100644 --- a/exercises/064-getAllWords/app.js +++ b/exercises/064-getAllWords/app.js @@ -1,5 +1,7 @@ function getAllWords(str) { // your code here + let palabras = str.split(" ") + return palabras } diff --git a/exercises/065-or/app.js b/exercises/065-or/app.js index f9643545d..7b079571b 100644 --- a/exercises/065-or/app.js +++ b/exercises/065-or/app.js @@ -1,5 +1,15 @@ function or(expression1, expression2) { // your code here + let buleano = false + + if(expression1 === false && expression2 === false){ + buleano = false; + } + else { + buleano = true; + } + + return buleano } diff --git a/exercises/066-extend/app.js b/exercises/066-extend/app.js index c2e6f68a0..b7dbe1227 100644 --- a/exercises/066-extend/app.js +++ b/exercises/066-extend/app.js @@ -9,5 +9,11 @@ let obj2 = { function extend(obj1, obj2) { // your code here + for (let i in obj2) { + if(!(i in obj1)){ + obj1[i] = obj2[i] + } + } +} -} \ No newline at end of file +console.log(obj1) \ No newline at end of file diff --git a/exercises/067-removeNumbersLargerThan/app.js b/exercises/067-removeNumbersLargerThan/app.js index 83bf4b8f1..e42831eab 100644 --- a/exercises/067-removeNumbersLargerThan/app.js +++ b/exercises/067-removeNumbersLargerThan/app.js @@ -6,5 +6,11 @@ let obj = { function removeNumbersLargerThan(num, obj) { // your code here - + for (let i in obj){ + if(typeof(obj[i]) === "number" && obj[i] > num) { + delete obj[i] + } + } + + return obj } diff --git a/exercises/068-removeNumbersLessThan/app.js b/exercises/068-removeNumbersLessThan/app.js index bed771763..f79476b8d 100644 --- a/exercises/068-removeNumbersLessThan/app.js +++ b/exercises/068-removeNumbersLessThan/app.js @@ -6,5 +6,12 @@ let obj = { function removeNumbersLessThan(num, obj) { // your code here - + for (let i in obj){ + if(typeof(obj[i]) === "number" && obj[i] < num){ + delete obj[i] + } + } + return obj } + +removeNumbersLessThan(5, obj); diff --git a/exercises/069-removeStringValuesLongerThan/app.js b/exercises/069-removeStringValuesLongerThan/app.js index 062756977..3cb00d20e 100644 --- a/exercises/069-removeStringValuesLongerThan/app.js +++ b/exercises/069-removeStringValuesLongerThan/app.js @@ -1,6 +1,11 @@ function removeStringValuesLongerThan(num, obj) { // your code here - + for (let i in obj) { + if(typeof(obj[i]) === "string" && obj[i].length > num){ + delete obj[i] + } + } + return obj } let obj = { diff --git a/exercises/070-removeEvenValues/app.js b/exercises/070-removeEvenValues/app.js index 1d82a7105..185041242 100644 --- a/exercises/070-removeEvenValues/app.js +++ b/exercises/070-removeEvenValues/app.js @@ -1,6 +1,11 @@ function removeEvenValues(obj) { // your code here - + for( let i in obj){ + if( typeof(obj[i]) === "number" && obj[i] % 2 === 0 ){ + delete obj[i] + } + } + return obj } let obj = { diff --git a/exercises/071-countNumberOfKeys/app.js b/exercises/071-countNumberOfKeys/app.js index 35a475c97..bf2ba99cc 100644 --- a/exercises/071-countNumberOfKeys/app.js +++ b/exercises/071-countNumberOfKeys/app.js @@ -9,7 +9,13 @@ let obj = { function countNumberOfKeys(obj) { // your code here - + let llaves = 0; + + for(let i in obj){ + llaves += 1 + } + + return llaves } let output = countNumberOfKeys(obj); diff --git a/exercises/072-removeOddValues/app.js b/exercises/072-removeOddValues/app.js index a5a19c538..ad2d8d85c 100644 --- a/exercises/072-removeOddValues/app.js +++ b/exercises/072-removeOddValues/app.js @@ -1,6 +1,10 @@ function removeOddValues(obj) { // your code here - + for (let i in obj) { + if( typeof(obj[i]) === "number" && obj[i] % 2 !== 0 ){ + delete obj[i] + } + } } let obj = { diff --git a/exercises/073-removeArrayValues/app.js b/exercises/073-removeArrayValues/app.js index 295a2a3ae..ed87e0092 100644 --- a/exercises/073-removeArrayValues/app.js +++ b/exercises/073-removeArrayValues/app.js @@ -1,4 +1,19 @@ function removeArrayValues(obj) { // your code here - -} \ No newline at end of file + for( let i in obj) { + if( Array.isArray(obj[i]) ) { + delete obj[i] + } + } + + + return obj; +} + +let obj = { + a: [1, 3, 4], + b: 2, + c: ['hi', 'there'] +} + +removeArrayValues(obj) \ No newline at end of file diff --git a/exercises/074-removeNumberValues/app.js b/exercises/074-removeNumberValues/app.js index 7bf955613..fb6054ab0 100644 --- a/exercises/074-removeNumberValues/app.js +++ b/exercises/074-removeNumberValues/app.js @@ -1,6 +1,11 @@ function removeNumberValues(obj) { // your code here - + for(let i in obj) { + if( typeof(obj[i]) === "number"){ + delete obj[i] + } + } + return obj } let obj = { diff --git a/exercises/075-removeStringValues/app.js b/exercises/075-removeStringValues/app.js index 32d2afaad..4c467f55a 100644 --- a/exercises/075-removeStringValues/app.js +++ b/exercises/075-removeStringValues/app.js @@ -1,6 +1,11 @@ function removeStringValues(obj) { // your code here - + for(let i in obj){ + if( typeof(obj[i]) === "string"){ + delete obj[i] + } + } + return obj } let obj = { diff --git a/exercises/076-convertDoubleSpaceToSingle/app.js b/exercises/076-convertDoubleSpaceToSingle/app.js index ed0a2e7cf..cd1bed6ff 100644 --- a/exercises/076-convertDoubleSpaceToSingle/app.js +++ b/exercises/076-convertDoubleSpaceToSingle/app.js @@ -1,6 +1,10 @@ function convertDoubleSpaceToSingle(str) { // your code here + let string_v1 = str.split(" ") + + let string_v2 = string_v1.join( " ") + return string_v2 } let output = convertDoubleSpaceToSingle("string with double spaces"); diff --git a/exercises/077-areValidCredentials/app.js b/exercises/077-areValidCredentials/app.js index 3e2df3368..aad416ec6 100644 --- a/exercises/077-areValidCredentials/app.js +++ b/exercises/077-areValidCredentials/app.js @@ -1 +1,13 @@ -// Write your function here +function areValidCredentials(name, password){ + let valida = false + + if ( password.length >= 8 && name.length > 3 ){ + valida = true + } + + + return valida +} + +let output = areValidCredentials('Ritu', 'mylongpassword') +console.log(output); \ No newline at end of file diff --git a/exercises/078-getIndexOf/app.js b/exercises/078-getIndexOf/app.js index 3e2df3368..ed89f2a5c 100644 --- a/exercises/078-getIndexOf/app.js +++ b/exercises/078-getIndexOf/app.js @@ -1 +1,18 @@ // Write your function here +function getIndexOf(letra, string){ + + let index = 0; + + for (let i = 0; i < string.length; i++) { + if ( string[i] === letra ){ + return i + + } + + } + + return -1 +} + +let output = getIndexOf('a', 'I am a hacker'); +console.log(output); \ No newline at end of file diff --git a/exercises/079-findMinLengthOfThreeWords/app.js b/exercises/079-findMinLengthOfThreeWords/app.js index 6ebc804ae..ef29e1529 100644 --- a/exercises/079-findMinLengthOfThreeWords/app.js +++ b/exercises/079-findMinLengthOfThreeWords/app.js @@ -1 +1,10 @@ -// Write your function here \ No newline at end of file +// Write your function here +function findMinLengthOfThreeWords(str1, str2, str3){ + + let minimo = Math.min(str1.length, str2.length, str3.length) + + return minimo +} + +let output = findMinLengthOfThreeWords('a', 'be', 'see'); +console.log(output) \ No newline at end of file diff --git a/exercises/080-findMaxLengthOfThreeWords/app.js b/exercises/080-findMaxLengthOfThreeWords/app.js index 6ebc804ae..add56f005 100644 --- a/exercises/080-findMaxLengthOfThreeWords/app.js +++ b/exercises/080-findMaxLengthOfThreeWords/app.js @@ -1 +1,7 @@ -// Write your function here \ No newline at end of file +// Write your function here +function findMaxLengthOfThreeWords(num1, num2, num3){ + return Math.max(num1.length, num2.length, num3.length) +} + +let output = findMaxLengthOfThreeWords('a', 'be', 'see'); +console.log(output) \ No newline at end of file diff --git a/exercises/081-repeatString/app.js b/exercises/081-repeatString/app.js index 36391aad4..00f99e35e 100644 --- a/exercises/081-repeatString/app.js +++ b/exercises/081-repeatString/app.js @@ -1,5 +1,9 @@ function repeatString(string, num) { - // your code here + + + + + return string.repeat(num) } diff --git a/exercises/082-getLongestOfThreeWords/app.js b/exercises/082-getLongestOfThreeWords/app.js index 42b3ac7d6..42c11163a 100644 --- a/exercises/082-getLongestOfThreeWords/app.js +++ b/exercises/082-getLongestOfThreeWords/app.js @@ -1,6 +1,20 @@ function getLongestOfThreeWords(word1, word2, word3) { // your code here - + let palabra = 0; + + switch(Math.max(word1.length, word2.length, word3.length)){ + case word1.length: + palabra = word1; + break; + case word2.length: + palabra = word2; + break; + case word3.length: + palabra = word3; + break; + } + + return palabra } let output = getLongestOfThreeWords('these', 'three', 'words'); diff --git a/exercises/083-findShortestOfThreeWords/app.js b/exercises/083-findShortestOfThreeWords/app.js index 7f9005ba1..0be03a073 100644 --- a/exercises/083-findShortestOfThreeWords/app.js +++ b/exercises/083-findShortestOfThreeWords/app.js @@ -1,6 +1,19 @@ function findShortestOfThreeWords(word1, word2, word3) { // your code here - + let menor = 0 + + switch(Math.min(word1.length, word2.length, word3.length)){ + case word1.length: + menor = word1; + break; + case word2.length: + menor = word2; + break; + case word3.length: + menor = word3; + break; + } + return menor } let output = findShortestOfThreeWords('a', 'two', 'three'); diff --git a/exercises/084-joinThreeArrays/app.js b/exercises/084-joinThreeArrays/app.js index 13bb8c197..c812bd4ff 100644 --- a/exercises/084-joinThreeArrays/app.js +++ b/exercises/084-joinThreeArrays/app.js @@ -1,4 +1,7 @@ function joinThreeArrays(arr1, arr2, arr3) { // your code here - -} \ No newline at end of file + return arr1.concat(arr2, arr3) +} + +let output = joinThreeArrays([1, 2], [3, 4], [5, 6]); +console.log(output); \ No newline at end of file diff --git a/exercises/085-addToFrontOfNew/app.js b/exercises/085-addToFrontOfNew/app.js index 2e213064c..ce04af7c2 100644 --- a/exercises/085-addToFrontOfNew/app.js +++ b/exercises/085-addToFrontOfNew/app.js @@ -1,9 +1,7 @@ function addToFrontOfNew(arr, element) { - // your code here - + // your code here + + return [element].concat(arr) } -let input = [1, 2]; -let output = addToFrontOfNew(input, 3); -console.log(output); // --> [3, 1, 2]; -console.log(input); // --> [1, 2] +let output = addToFrontOfNew([1, 2], 3); \ No newline at end of file diff --git a/exercises/086-addToBackOfNew/app.js b/exercises/086-addToBackOfNew/app.js index ad99f9609..b26e66ecc 100644 --- a/exercises/086-addToBackOfNew/app.js +++ b/exercises/086-addToBackOfNew/app.js @@ -1,6 +1,8 @@ function addToBackOfNew(arr, element) { // your code here - + let new_array = arr.push(element) + + return new_array } let input = [1, 2]; diff --git a/exercises/087-getAllElementsButNth/app.js b/exercises/087-getAllElementsButNth/app.js index b5986c5b2..c84eb17ab 100644 --- a/exercises/087-getAllElementsButNth/app.js +++ b/exercises/087-getAllElementsButNth/app.js @@ -1,6 +1,7 @@ function getAllElementsButNth(array, n) { // your code here - + array.splice(n, 1) + return array } let output = getAllElementsButNth(['a', 'b', 'c'], 1); diff --git a/exercises/088-keep/app.js b/exercises/088-keep/app.js index 3e2df3368..9c37255e5 100644 --- a/exercises/088-keep/app.js +++ b/exercises/088-keep/app.js @@ -1 +1,11 @@ // Write your function here +function keep(array, num){ + + let resultado = array.filter(i => i === num ) + + return resultado + +} + +let output = keep([1, 2, 3, 2, 1], 2) +console.log(output); \ No newline at end of file diff --git a/exercises/089-removeElement/app.js b/exercises/089-removeElement/app.js index 3e2df3368..127a47896 100644 --- a/exercises/089-removeElement/app.js +++ b/exercises/089-removeElement/app.js @@ -1 +1,12 @@ // Write your function here +function removeElement(array, num){ + + let new_array = [] + + new_array = array.filter(i => i !== num) + + return new_array +} + +let output = removeElement([1, 2, 3, 2, 1], 2); +console.log(output); \ No newline at end of file diff --git a/exercises/090-filterOddLengthWords/app.js b/exercises/090-filterOddLengthWords/app.js index ec065e3e4..02b4b9642 100644 --- a/exercises/090-filterOddLengthWords/app.js +++ b/exercises/090-filterOddLengthWords/app.js @@ -1,6 +1,13 @@ function filterOddLengthWords(words) { // your code here - + let new_list = [] + + for (let i in words){ + if(words[i].length % 2 !== 0){ + new_list.push(words[i]) + } + } + return new_list } let output = filterOddLengthWords(['there', 'it', 'is', 'now']); diff --git a/exercises/091-filterEvenLengthWords/app.js b/exercises/091-filterEvenLengthWords/app.js index 88104f97b..26acfa4ef 100644 --- a/exercises/091-filterEvenLengthWords/app.js +++ b/exercises/091-filterEvenLengthWords/app.js @@ -1,6 +1,14 @@ function filterEvenLengthWords(words) { // your code here + let lista = [] + + for(let i in words){ + if(words[i].length % 2 === 0){ + lista.push(words[i]) + } + } + return lista } let output = filterEvenLengthWords(['word', 'words', 'word', 'words']); diff --git a/exercises/092-getFirstElementOfProperty/app.js b/exercises/092-getFirstElementOfProperty/app.js index 3e2df3368..4a2e71e58 100644 --- a/exercises/092-getFirstElementOfProperty/app.js +++ b/exercises/092-getFirstElementOfProperty/app.js @@ -1 +1,16 @@ // Write your function here +function getFirstElementOfProperty(obj, llave){ + + if (!Array.isArray(obj[llave])) { + return undefined; + } + + return obj[llave][0] +} + +let obj = { + key: [1, 2, 4] +}; + +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..cb92b3c57 100644 --- a/exercises/093-getNthElementOfProperty/app.js +++ b/exercises/093-getNthElementOfProperty/app.js @@ -1 +1,14 @@ // Write your function here +function getNthElementOfProperty(objeto, llave, posicion){ + if(!Array.isArray(objeto[llave])){ + return undefined + } + return objeto[llave][posicion] +} + + +let obj = { + key: [1, 2, 6] +}; +let output = getNthElementOfProperty(obj, 'key', 1); +console.log(output); \ No newline at end of file diff --git a/exercises/094-getLastElementOfProperty/app.js b/exercises/094-getLastElementOfProperty/app.js index 3e2df3368..2c8cdc9eb 100644 --- a/exercises/094-getLastElementOfProperty/app.js +++ b/exercises/094-getLastElementOfProperty/app.js @@ -1 +1,17 @@ // Write your function here + +function getLastElementOfProperty(objeto, llave){ + + if(!Array.isArray(objeto[llave])){ + return undefined + } + + return objeto[llave][objeto[llave].length - 1] +} + +let obj = { + key: [1, 2, 5] +}; + +let output = getLastElementOfProperty(obj, 'key'); +console.log(output); \ No newline at end of file diff --git a/exercises/095-getElementsThatEqual10AtProperty/app.js b/exercises/095-getElementsThatEqual10AtProperty/app.js index 3e2df3368..10f83ac44 100644 --- a/exercises/095-getElementsThatEqual10AtProperty/app.js +++ b/exercises/095-getElementsThatEqual10AtProperty/app.js @@ -1 +1,23 @@ -// Write your function here +function getElementsThatEqual10AtProperty(objeto, llave){ + + let arreglo = [] + + if (!Array.isArray(objeto[llave])){ + return arreglo = [] + } + + + + for(let i in objeto[llave]){ + if(objeto[llave][i] === 10){ + arreglo.push(objeto[llave][i]) + } + } + + return arreglo +} +let obj = { + key: [1000, 10, 50, 10] +}; +let output = getElementsThatEqual10AtProperty(obj, 'key'); +console.log(output); \ No newline at end of file diff --git a/exercises/096-getElementsLessThanOneHundredAtProperty/app.js b/exercises/096-getElementsLessThanOneHundredAtProperty/app.js index 3e2df3368..3cb4cdfba 100644 --- a/exercises/096-getElementsLessThanOneHundredAtProperty/app.js +++ b/exercises/096-getElementsLessThanOneHundredAtProperty/app.js @@ -1 +1,25 @@ // Write your function here +function getElementsLessThan100AtProperty(objeto, llave) { + + let result = [] + + if (!Array.isArray(objeto[llave])){ + return result + } + + for(let i in objeto[llave]){ + if(objeto[llave][i] < 100){ + result.push(objeto[llave][i]) + } + } + + + return result +} + +let obj = { + key: [1000, 20, 50, 500] +}; + +let output = getElementsLessThan100AtProperty(obj, 'key'); +console.log(output); \ No newline at end of file diff --git a/exercises/097-getElementsGreaterThanTenAtProperty/app.js b/exercises/097-getElementsGreaterThanTenAtProperty/app.js index 3e2df3368..0bfd5d139 100644 --- a/exercises/097-getElementsGreaterThanTenAtProperty/app.js +++ b/exercises/097-getElementsGreaterThanTenAtProperty/app.js @@ -1 +1,23 @@ // Write your function here +function getElementsGreaterThan10AtProperty(obj, key){ + + let result = [] + + if(!Array.isArray(obj[key])){ + result = [] + } + + for(let i in obj[key]){ + if (obj[key][i] > 10){ + result.push(obj[key][i]) + } + } + + return result +} + +let obj = { + key: [1, 20, 30] +}; +let output = getElementsGreaterThan10AtProperty(obj, 'key'); +console.log(output); \ No newline at end of file diff --git a/exercises/098-getOddLengthWordsAtProperty/app.js b/exercises/098-getOddLengthWordsAtProperty/app.js index 3e2df3368..c3c09ce74 100644 --- a/exercises/098-getOddLengthWordsAtProperty/app.js +++ b/exercises/098-getOddLengthWordsAtProperty/app.js @@ -1 +1,22 @@ // Write your function here +function getOddLengthWordsAtProperty(obj, key){ + + let result = [] + + if(!Array.isArray(obj[key])){ + return result; + } + + for( let i in obj[key]){ + if(obj[key][i].length % 2 !== 0 ){ + result.push(obj[key][i]) + } + } + return result +} + +let obj = { + key: ['It', 'has', 'some', 'words'] +}; +let output = getOddLengthWordsAtProperty(obj, 'key'); +console.log(output); \ No newline at end of file diff --git a/exercises/099-getAverageOfElementsAtProperty/app.js b/exercises/099-getAverageOfElementsAtProperty/app.js index 8339aa1d1..bd7227be9 100644 --- a/exercises/099-getAverageOfElementsAtProperty/app.js +++ b/exercises/099-getAverageOfElementsAtProperty/app.js @@ -1,4 +1,28 @@ function getAverageOfElementsAtProperty(obj, key) { // your code here + let suma = 0 + if(!(key in obj)){ + return 0; + } + if(obj[key].length === 0){ + return 0; + } else if (!Array.isArray(obj[key])){ + return 0; + } else + -} \ No newline at end of file + + for(let i in obj[key]){ + suma += obj[key][i] + } + + let result = suma / obj[key].length; + + return result +} + +let obj = { + key: [1, 2, 3] +}; +let output = getAverageOfElementsAtProperty(obj, 'key'); +console.log(output); \ No newline at end of file diff --git a/exercises/100-getEvenLengthWordsAtProperty/app.js b/exercises/100-getEvenLengthWordsAtProperty/app.js index 1ba09c698..08c86dfb3 100644 --- a/exercises/100-getEvenLengthWordsAtProperty/app.js +++ b/exercises/100-getEvenLengthWordsAtProperty/app.js @@ -1,6 +1,18 @@ function getEvenLengthWordsAtProperty(obj, key) { // your code here - + let result = []; + + if (!obj[key] || !Array.isArray(obj[key])) { + return result; + } + + for (let i = 0; i < obj[key].length; i++){ + if (typeof obj[key][i] === 'string' && obj[key][i].length % 2 === 0) { + result.push(obj[key][i]); + } + } + + return result; } let obj = { diff --git a/exercises/101-getOddElementsAtProperty/app.js b/exercises/101-getOddElementsAtProperty/app.js index 163577f1c..0d47af818 100644 --- a/exercises/101-getOddElementsAtProperty/app.js +++ b/exercises/101-getOddElementsAtProperty/app.js @@ -1,8 +1,21 @@ function getOddElementsAtProperty(obj, key) { // your code here - + let result = [] + + if(!obj[key] || !Array.isArray(obj[key]) || obj[key].length === 0){ + return result + } + + for(let i = 0; i < obj[key].length; i++){ + if( obj[key][i] % 2 !== 0 ){ + result.push(obj[key][i]) + } + } + + return result } + let obj = { key: [1, 2, 3, 4, 5] }; diff --git a/exercises/102-getEvenElementsAtProperty/app.js b/exercises/102-getEvenElementsAtProperty/app.js index 28b5d8a00..341d80cd7 100644 --- a/exercises/102-getEvenElementsAtProperty/app.js +++ b/exercises/102-getEvenElementsAtProperty/app.js @@ -1,6 +1,18 @@ function getEvenElementsAtProperty(obj, key) { // your code here - + let result = [] + + if(!obj[key] || !Array.isArray(obj[key] || obj[key].length === 0)){ + return result + } + + for(let i=0; i= obj[key].length){ + resultado = undefined + } + + + return resultado } let obj = { diff --git a/exercises/108-getProductOfAllElementsAtProperty/app.js b/exercises/108-getProductOfAllElementsAtProperty/app.js index 6c619b509..d2f87fda2 100644 --- a/exercises/108-getProductOfAllElementsAtProperty/app.js +++ b/exercises/108-getProductOfAllElementsAtProperty/app.js @@ -1,6 +1,20 @@ function getProductOfAllElementsAtProperty(obj, key) { // your code here - + let result = 1; + + if(!obj[key] || !Array.isArray(obj[key]) || obj[key].length === 0){ + return result = 0 + } + + for(let i=0; i= obj[key].length){ + result = 0 + } + + return result } let obj = { diff --git a/exercises/109-Select/app.js b/exercises/109-Select/app.js index 3e2df3368..2186f3146 100644 --- a/exercises/109-Select/app.js +++ b/exercises/109-Select/app.js @@ -1 +1,27 @@ -// Write your function here +function select(array, objeto) { + let resultado = {}; + + for (let i = 0; i < array.length; i++) { + let clave = array[i]; + + if (objeto.hasOwnProperty(clave)) { + resultado[clave] = objeto[clave]; + } + } + + return resultado; +} + + +let arr = ['a', 'c', 'e']; + +let obj = { + a: 1, + b: 2, + c: 3, + d: 4 +}; +let output = select(arr, obj); +console.log(output); + + diff --git a/exercises/110-getSumOfAllElementsAtProperty/app.js b/exercises/110-getSumOfAllElementsAtProperty/app.js index 3a48d860a..8ff532aad 100644 --- a/exercises/110-getSumOfAllElementsAtProperty/app.js +++ b/exercises/110-getSumOfAllElementsAtProperty/app.js @@ -1,6 +1,16 @@ function getSumOfAllElementsAtProperty(obj, key) { // your code here - + let resultado = 0; + + if(!obj[key] || !Array.isArray(obj[key]) || obj[key].length === 0 ){ + return resultado + } + + for( let i = 0; i mayorLongitud) { + mayorLongitud = arr[i].length; + } + } + + return mayorLongitud; } + let output = getLengthOfLongestElement(['one', 'two', 'three']); console.log(output); // --> 5 diff --git a/exercises/113-squareElements/app.js b/exercises/113-squareElements/app.js index bd4906062..92a0bfd31 100644 --- a/exercises/113-squareElements/app.js +++ b/exercises/113-squareElements/app.js @@ -1,6 +1,12 @@ function squareElements(arr) { // your code here - + let array_cudrado = [] + + for(let i=0; i longest.length){ + longest = arr[i] + } + } + + return longest } let output = getLongestElement(['one', 'two', 'three']); diff --git a/exercises/119-findSmallestElement/app.js b/exercises/119-findSmallestElement/app.js index 4126bd57d..bea1ae5a0 100644 --- a/exercises/119-findSmallestElement/app.js +++ b/exercises/119-findSmallestElement/app.js @@ -1,6 +1,14 @@ function findSmallestElement(arr) { // your code here + if (arr.length === 0){ + return 0 + } + let smallest = 0; + + smallest = Math.min(...arr) + + return smallest } let output = findSmallestElement([4, 1, 9, 10]); diff --git a/exercises/120-findShortestElement/app.js b/exercises/120-findShortestElement/app.js index bff07f040..4b33a0235 100644 --- a/exercises/120-findShortestElement/app.js +++ b/exercises/120-findShortestElement/app.js @@ -1,7 +1,6 @@ function findShortestElement(arr) { // your code here - + } - let output = findShortestElement(['a', 'two', 'three']); 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..e019502dd 100644 --- a/exercises/121-getLargestElement/app.js +++ b/exercises/121-getLargestElement/app.js @@ -1,6 +1,18 @@ function getLargestElement(arr) { // your code here - + if(arr.length === 0){ + return 0 + } + + let largest = arr[0] + + for(let i = 0; i < arr.length; i++){ + if(arr[i] > largest){ + largest = arr[i] + } + } + + return largest } let output = getLargestElement([5, 2, 8, 3]); diff --git a/exercises/122-computeSumOfAllElements/app.js b/exercises/122-computeSumOfAllElements/app.js index 606800a9f..2bed483f9 100644 --- a/exercises/122-computeSumOfAllElements/app.js +++ b/exercises/122-computeSumOfAllElements/app.js @@ -1,6 +1,12 @@ function computeSumOfAllElements(arr) { // your code here + let result = 0; + + for( let i = 0; i < arr.length; i++){ + result += arr[i] + } + return result } let output = computeSumOfAllElements([1, 2, 3]) diff --git a/exercises/123-joinArraysOfArrays/app.js b/exercises/123-joinArraysOfArrays/app.js index 16b69107c..4c96f63f6 100644 --- a/exercises/123-joinArraysOfArrays/app.js +++ b/exercises/123-joinArraysOfArrays/app.js @@ -1,6 +1,10 @@ function joinArrayOfArrays(arr) { // your code here - + let concatenado = "" + + concatenado = arr[0].concat(arr[1], arr[2]) + + return concatenado } let output = joinArrayOfArrays([ diff --git a/exercises/124-findShortestWordAmongMixedElements/app.js b/exercises/124-findShortestWordAmongMixedElements/app.js index 656547df3..beb1740de 100644 --- a/exercises/124-findShortestWordAmongMixedElements/app.js +++ b/exercises/124-findShortestWordAmongMixedElements/app.js @@ -1,6 +1,25 @@ function findShortestWordAmongMixedElements(arr) { // your code here + if(arr.length === 0){ + return ""; + } + let shortest = ""; + let firstStringFound = false; + + for(let i=0; i longest){ + longest = arr[i] + } + } + } + + return longest } let output = getLongestWordOfMixedElements([3, 'word', 5, 'up', 3, 1]); diff --git a/exercises/127-getLargestNumberAmongMixedElements/app.js b/exercises/127-getLargestNumberAmongMixedElements/app.js index 2599e198c..d2d357eee 100644 --- a/exercises/127-getLargestNumberAmongMixedElements/app.js +++ b/exercises/127-getLargestNumberAmongMixedElements/app.js @@ -1,6 +1,18 @@ function getLargestNumberAmongMixedElements(arr) { // your code here - + if(arr.length === 0){ + return 0 + } + + let largest = 0 + + for(let i=0; i largest){ + largest = arr[i] + } + } + + return largest } let output = getLargestNumberAmongMixedElements([3, 'word', 5, 'up', 3, 1]); diff --git a/exercises/128-averageIntegers/app.js b/exercises/128-averageIntegers/app.js index c9fb36856..b384faa59 100644 --- a/exercises/128-averageIntegers/app.js +++ b/exercises/128-averageIntegers/app.js @@ -1,11 +1,21 @@ function average(arr) { // your code here - + let average = 0 + + average = sum(arr) / arr.length + + return average } function sum(arr) { // your code here - + let suma = 0 + + for(let i=0; i 1.5 diff --git a/exercises/129-calculateBillTotal/app.js b/exercises/129-calculateBillTotal/app.js index a807a9280..03d8ec377 100644 --- a/exercises/129-calculateBillTotal/app.js +++ b/exercises/129-calculateBillTotal/app.js @@ -1,6 +1,9 @@ function calculateBillTotal(preTaxAndTipAmount) { // your code here - + let tax = preTaxAndTipAmount * 0.15; + let tip = preTaxAndTipAmount * 0.095; + let total = preTaxAndTipAmount + tax + tip; + return total } let output = calculateBillTotal(20); diff --git a/exercises/130-multiplyBetween/app.js b/exercises/130-multiplyBetween/app.js index bcd2f469f..a229e0e10 100644 --- a/exercises/130-multiplyBetween/app.js +++ b/exercises/130-multiplyBetween/app.js @@ -1,6 +1,17 @@ function multiplyBetween(num1, num2) { - // your code here + + if(num2 < num1){ + return 0 + } + + let total = 1 + + for (let i = num1; i = num2; i++){ + total *= i + } + + return total } let output = multiplyBetween(2, 5); diff --git a/exercises/131-computeSumBetween/app.js b/exercises/131-computeSumBetween/app.js index ef0828c81..dee43828e 100644 --- a/exercises/131-computeSumBetween/app.js +++ b/exercises/131-computeSumBetween/app.js @@ -1,6 +1,16 @@ function computeSumBetween(num1, num2) { // your code here + if(num2 < num1){ + return 0 + } + let total = 0 + + for( let i=num1 ; i