diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..abdd76a Binary files /dev/null and b/.DS_Store differ diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5a19a93 --- /dev/null +++ b/.gitignore @@ -0,0 +1,20 @@ +# configuration and readme +!.gitignore +!.gitpod.yml +!.gitpod.Dockerfile +!learn.json +!README.md + +# exercises +!.learn/ +!.learn/* +.learn/_app +.learn/.session +.learn/dist +.learn/app.tar.gz +.learn/config.json + +# python compiled files +*.pyc +__pycache__/ +.pytest_cache/ \ No newline at end of file diff --git a/.gitpod.dockerfile b/.gitpod.dockerfile new file mode 100644 index 0000000..4fdad7a --- /dev/null +++ b/.gitpod.dockerfile @@ -0,0 +1,7 @@ +FROM gitpod/workspace-full:latest + +USER gitpod + +RUN npm i jest@24.8.0 -g + +RUN npm i @learnpack/learnpack -g && learnpack plugins:install @learnpack/node \ No newline at end of file diff --git a/.gitpod.yml b/.gitpod.yml new file mode 100644 index 0000000..816c5fc --- /dev/null +++ b/.gitpod.yml @@ -0,0 +1,19 @@ +image: + file: .gitpod.dockerfile + +ports: + - port: 3000 + onOpen: ignore + +vscode: + extensions: + - learn-pack.learnpack-vscode + +github: + prebuilds: + # enable for the master/default branch (defaults to true) + master: true + # enable for pull requests coming from this repo (defaults to true) + pullRequests: false + # add a "Review in Gitpod" button as a comment to pull requests (defaults to true) + addComment: false \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..c4165dc --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.autoSave": "afterDelay", + "files.autoSaveDelay": 700, + "editor.minimap.enabled": false +} diff --git a/README.es.md b/README.es.md new file mode 100644 index 0000000..26faa3a --- /dev/null +++ b/README.es.md @@ -0,0 +1,133 @@ +# Desafíos de codificación JavaScript :computadora: +Este repositorio contiene un conjunto de desafíos de programación JavaScript junto con las soluciones. + +**Preguntas de desafío:** +Todos los desafíos se enumeran a continuación. + +**Soluciones:** +Los enlaces a las soluciones se proporcionan debajo de las preguntas. + +**Abrir desafios con learnpack:** + +[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io#https://github.com/rahni1/javascript-challenges.git) + +RETOS: + +**1. Validacion de Números:** + Haga que la función ```checkNums(num1,num2)``` tome ambos parámetros que se pasan e imprima verdadero si num2 es mayor que num1, de lo contrario imprima falso. + Si los valores de los parámetros son iguales entre sí, imprima -1. + + **[Solución](https://github.com/RahniKaurBansal/JS-Challenges/blob/master/CheckNums.js)** + +**2. Comparar Strings:** + Cree una función que tome dos strings como argumentos y devuelva true o false + dependiendo de si el número total de caracteres en el primer string es igual a la + número total de caracteres en el segundo string. + +**[Solución](https://github.com/RahniKaurBansal/JS-Challenges/blob/master/CompareStrings.js)** + +**3. Concatenar Arrays:** + Cree una función para concatenar dos arrays de tipo int. + +**[Solución](https://github.com/RahniKaurBansal/JS-Challenges/blob/master/ConcatenateArrays.js)** + +**4. Contar las Vocales:** + Cree una función que tome un string e imprima el número de vocales que contiene. + + **[Solución](https://github.com/RahniKaurBansal/JS-Challenges/blob/master/VowelCount.js)** + +**5. Fecha y Hora:** 📅 + - Imprime la fecha y hora actuales en el formato predeterminado. + - Imprime la fecha y hora actual en estilo localizado. + - Imprime la fecha y hora actuales con un patrón. + + **[Solución](https://github.com/RahniKaurBansal/JS-Challenges/blob/master/DateTime.js)** + +**6. Divisible por 5:** + Cree una función que imprima true si un número entero es divisible por 5 y false en caso contrario. + + **[Solución](https://github.com/RahniKaurBansal/JS-Challenges/blob/master/DivisibleBy5.js)** + +**7. Factorial:** + Este desafío requiere que devuelvas el factorial de un número dado. El factorial de un numero + (num), es num multiplicado por (num-1) multiplicado por (num-2) y así sucesivamente hasta llegar al número 1. + Por ejemplo, el factorial de 4 es 4 * 3 * 2 * 1 = 24. Bucle de 1 a num, multiplicando cada número por + el anterior, hasta llegar al número. + + **[Solución](https://github.com/RahniKaurBansal/JS-Challenges/blob/master/Factorial.js)** + +**8. Fibonacci:** + La secuencia de Fibonacci es una secuencia de números cuya suma es los dos números anteriores (por ejemplo, 0, 1, 1, 2, 3, etc.). + Usando 0 y 1 como valores iniciales, cree una función que imprima un array que contenga todos los valores de Fibonacci + hasta el 10000. + +**[Solución](https://github.com/RahniKaurBansal/JS-Challenges/blob/master/Fibonacci.js)** + +**9. FizzBuzz:** + Escriba un programa que imprima los números del 1 al 100. Pero para múltiplos de tres, escriba "Fizz" en lugar de + el número y para los múltiplos de cinco escriba “Buzz”. Para números que son múltiplos de tres y cinco + imprime "FizzBuzz". + + **[Solución](https://github.com/RahniKaurBansal/JS-Challenges/blob/master/FizzBuzz.js)** + +**10. Letras en Mayúscula:** + Cree una función que convierta el primer carácter de cada palabra en mayúsculas. Imprime el string recién formateado. + + **[Solución](https://github.com/RahniKaurBansal/JS-Challenges/blob/master/CapitaliseEveryLetter.js)** + +**11. Multiplicar y Saltar:** + Imprime los múltiplos de 5 saltando los múltiplos de 3. + + **[Solución](https://github.com/RahniKaurBansal/JS-Challenges/blob/master/MultiplySkip.js)** + +**12.Cambio de Nombre:** + Cambie su apellido usando una función constructora, la función changeName y una instancia de objeto. + + **[Solución](https://github.com/RahniKaurBansal/JS-Challenges/blob/master/NameChange.js)** + +**13. Palíndromo:** + Dado un string de texto, imprime true o false indicando si el texto es o no un palíndromo. + Un palíndromo es una palabra, número u otra secuencia de caracteres que se lee igual hacia atrás que hacia adelante, + como "Ana" o "Otto". También puede crear un palíndromo de números enteros (int). + + **[Solución](https://github.com/RahniKaurBansal/JS-Challenges/blob/master/Palindrome.js)** + +**14. Eliminar Personajes:** + Elimina el primer y último carácter de un string. + + **[Solución](https://github.com/RahniKaurBansal/JS-Challenges/blob/master/RemoveChars.js)** + +**15. Comparte el Pastel:** 🍰 + Cree una función que determine si es posible o no compartir el pastel de manera justa dados estos tres + parámetros: + Partes totales, Destinatarios, Partes cada uno. + Está bien no usar todo el pastel. + Imprima true si el pastel se puede compartir por igual, de lo contrario imprima false. + + **[Solución](https://github.com/RahniKaurBansal/JS-Challenges/blob/master/SplitCake.js)** + +**16. Formatear Número de Teléfono:** +Cree una función que tome un array de 10 números entre 0 y 9 y devuelva un string de números con formato de número de teléfono. +La llamada a la función debería parecerse a algo como esto: ```formatPhoneNumber(4, 4, 1, 2, 3, 4, 5, 6, 7, 8).``` + +**[Solución](https://github.com/RahniKaurBansal/JS-Challenges/blob/master/FormatPhoneNumber.js)** + +**17. Halla el Área de un Triángulo:** + Escribe una función que tome la base y la altura de un triángulo e imprima su área. +**[Solución](https://github.com/RahniKaurBansal/JS-Challenges/blob/master/AreaOfTriangle.js)** + +**18. Palabra Más Larga:** +Escriba una función que tome (sen) como parámetro e imprima la palabra más larga en una oración. + +**[Solución](https://github.com/RahniKaurBansal/JS-Challenges/blob/master/LongestWord.js)** + +**19. Ángulo Faltante:** +Cree una función que clasifique el ángulo faltante como "agudo", "derecho" u "obtuso" según sus grados. Proporcione dos números como argumentos y calcule el grado faltante sumando los dos números y restándolo de 180. + +**[Solución](https://github.com/RahniKaurBansal/JS-Challenges/blob/master/missingAngle.js)** + +**20. Límite de Número:** +Escriba una función que tome tres argumentos numéricos (un número como entrada y los otros dos números que representan los puntos más bajo y más alto del rango). Si el número cae dentro del rango, imprima el número. +Si el número es menor que el límite inferior del rango, imprime el número del límite más bajo y si el número es mayor que el límite superior del rango, imprime el número del límite más alto. + +**[Solución](https://github.com/RahniKaurBansal/JS-Challenges/blob/master/limitNumValue.js)** diff --git a/README.md b/README.md index dfc86e5..fbafaa9 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,10 @@ All of the challenges are listed below. **Solutions:** The links to the solutions are provided below the questions. +**Open challenges with learnpack:** + +[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io#https://github.com/rahni1/javascript-challenges.git) + CHALLENGES: **1. Check Nums:** diff --git a/exercises/01-CheckNums/README.es.md b/exercises/01-CheckNums/README.es.md new file mode 100644 index 0000000..75419af --- /dev/null +++ b/exercises/01-CheckNums/README.es.md @@ -0,0 +1,7 @@ +# `01` Check Nums + +Haz que la funcion checkNums(num1,num2) tome lo dos parametros siendo pasados. + +## Instrucciones 🗒 +1. Retorna `true` si `num2` es mayor que `num1`, de lo contrario retorna `false`. +2. Si los paremetros son iguales retorna `-1`. \ No newline at end of file diff --git a/exercises/01-CheckNums/README.md b/exercises/01-CheckNums/README.md new file mode 100644 index 0000000..3bb710d --- /dev/null +++ b/exercises/01-CheckNums/README.md @@ -0,0 +1,7 @@ +# `01` Check Nums + +Have the function checkNums(num1,num2) take both parameters being passed. + +## Instructions 🗒 +1. Return true if `num2` is greater than `num1`, otherwise return `false`. +2. If the parameter values are equal to each other then return `-1`. \ No newline at end of file diff --git a/exercises/01-CheckNums/app.js b/exercises/01-CheckNums/app.js new file mode 100644 index 0000000..3e203df --- /dev/null +++ b/exercises/01-CheckNums/app.js @@ -0,0 +1 @@ +// your code here diff --git a/exercises/01-CheckNums/solution.hide.js b/exercises/01-CheckNums/solution.hide.js new file mode 100644 index 0000000..956d645 --- /dev/null +++ b/exercises/01-CheckNums/solution.hide.js @@ -0,0 +1,4 @@ +// your code here +function checkNums(num1, num2) { + return num2 > num1 ? true : num1 > num2 ? false : -1; +} \ No newline at end of file diff --git a/exercises/01-CheckNums/test.js b/exercises/01-CheckNums/test.js new file mode 100644 index 0000000..f46d3c0 --- /dev/null +++ b/exercises/01-CheckNums/test.js @@ -0,0 +1,22 @@ +const rewire = require("rewire"); +const app = rewire("./app.js"); + +test('There should be a checkNums function', () => { + const checkNums = app.__get__("checkNums"); + expect(checkNums).toBeTruthy(); +}) + +test('If num2 is bigger than num1 you should return true', () => { + const checkNums = app.__get__("checkNums"); + expect(checkNums(4, 23)).toBe(true); +}); + +test("If num2 is less than num1 you should return false", () => { + const checkNums = app.__get__("checkNums"); + expect(checkNums(23, 4)).toBe(false); +}); + +test("If num1 is EQUAL to num2 you should return -1", () => { + const checkNums = app.__get__("checkNums"); + expect(checkNums(5, 5)).toBe(-1); +}); \ No newline at end of file diff --git a/exercises/02-CompareStrings/README.es.md b/exercises/02-CompareStrings/README.es.md new file mode 100644 index 0000000..13696ef --- /dev/null +++ b/exercises/02-CompareStrings/README.es.md @@ -0,0 +1,6 @@ +# `02` Compare Strings + +Crea una funcion `compareStrings` que toma dos strings como argumentos. + +## Instrucciones 🗒 +1. Retorna `true` o `false` dependiendo en que el total de caracteres en la primera string sea igual en tamanio al numero de caracters en la segunda string. \ No newline at end of file diff --git a/exercises/02-CompareStrings/README.md b/exercises/02-CompareStrings/README.md new file mode 100644 index 0000000..3b1a74a --- /dev/null +++ b/exercises/02-CompareStrings/README.md @@ -0,0 +1,6 @@ +# `02` Compare Strings + +Create a function `compareStrings` that takes two strings as arguments. + +## Instructions 🗒 +1. Return either `true` or `false` depending on whether the total number of characters in the first string is equal to the total number of characters in the second string. \ No newline at end of file diff --git a/exercises/02-CompareStrings/app.js b/exercises/02-CompareStrings/app.js new file mode 100644 index 0000000..851493a --- /dev/null +++ b/exercises/02-CompareStrings/app.js @@ -0,0 +1 @@ +// your code here \ No newline at end of file diff --git a/exercises/02-CompareStrings/solution.hide.js b/exercises/02-CompareStrings/solution.hide.js new file mode 100644 index 0000000..0caccc9 --- /dev/null +++ b/exercises/02-CompareStrings/solution.hide.js @@ -0,0 +1,8 @@ +// your code here +function compareStrings(string1, string2) { + if (string1.length === string2.length) { + return true; + } else { + return false; + } +} \ No newline at end of file diff --git a/exercises/02-CompareStrings/test.js b/exercises/02-CompareStrings/test.js new file mode 100644 index 0000000..8f293f6 --- /dev/null +++ b/exercises/02-CompareStrings/test.js @@ -0,0 +1,15 @@ +const rewire = require("rewire") +const app = rewire("./app.js") + +test('Function compareStrings should exist', ()=>{ + const compareStrings = app.__get__("compareStrings") + expect(compareStrings).toBeTruthy(); +}); +test('If the strings have the same length it should be true', ()=>{ + const compareStrings = app.__get__("compareStrings") + expect(compareStrings("hello", "table")).toBe(true); +}); +test('If the strings have the different lengths it should be false', ()=>{ + const compareStrings = app.__get__("compareStrings") + expect(compareStrings("zoo", "spectacular")).toBe(false); +}); \ No newline at end of file diff --git a/exercises/03-ConcatenateArrays/README.es.md b/exercises/03-ConcatenateArrays/README.es.md new file mode 100644 index 0000000..a7f708e --- /dev/null +++ b/exercises/03-ConcatenateArrays/README.es.md @@ -0,0 +1,5 @@ +# `03` Concatenate Arrays + +## Instrucciones 🗒 +1. Crea una funcion `concatenateIntArrays` que una dos `integer` arrays. +2. La funcion debe tomar `dos` arrays como argumento y retornar un `solo` array. diff --git a/exercises/03-ConcatenateArrays/README.md b/exercises/03-ConcatenateArrays/README.md new file mode 100644 index 0000000..9650ba6 --- /dev/null +++ b/exercises/03-ConcatenateArrays/README.md @@ -0,0 +1,5 @@ +# `03` Concatenate Arrays + +## Instructions 🗒 +1. Create a function `concatenateIntArrays` to concatenate two `integer` arrays. +2. The function should take `two` arrays as arguments and return a `single` array. \ No newline at end of file diff --git a/exercises/03-ConcatenateArrays/app.js b/exercises/03-ConcatenateArrays/app.js new file mode 100644 index 0000000..851493a --- /dev/null +++ b/exercises/03-ConcatenateArrays/app.js @@ -0,0 +1 @@ +// your code here \ No newline at end of file diff --git a/exercises/03-ConcatenateArrays/solution.hide.js b/exercises/03-ConcatenateArrays/solution.hide.js new file mode 100644 index 0000000..cd00a4f --- /dev/null +++ b/exercises/03-ConcatenateArrays/solution.hide.js @@ -0,0 +1,4 @@ +function concatenateIntArrays(array1, array2) { + const result = array1.concat(array2); + return result; +} \ No newline at end of file diff --git a/exercises/03-ConcatenateArrays/test.js b/exercises/03-ConcatenateArrays/test.js new file mode 100644 index 0000000..68f9bdb --- /dev/null +++ b/exercises/03-ConcatenateArrays/test.js @@ -0,0 +1,14 @@ +const rewire = require("rewire"); +const app = rewire("./app.js"); + +test("concatenateIntArrays function must exist.", () => { + const concatenateIntArrays = app.__get__("concatenateIntArrays"); + expect(concatenateIntArrays).toBeTruthy(); +}); + +test("The final output should be a mix of the two arrays", () => { + const concatenateIntArrays = app.__get__("concatenateIntArrays"); + + expect(concatenateIntArrays([2, 3, 4, 6], [7, 12, 32, 64])).toEqual([2, 3, 4, 6, 7, 12, 32, 64]); + expect(concatenateIntArrays([1, 2, 3, 4, 5], [6, 7, 8, 9, 10])).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); +}); diff --git a/exercises/04-VowelCount/README.es.md b/exercises/04-VowelCount/README.es.md new file mode 100644 index 0000000..d97b2a4 --- /dev/null +++ b/exercises/04-VowelCount/README.es.md @@ -0,0 +1,4 @@ +# `04` Vowel Counter + +## Instructions 🗒 +1. Crea una funcion que tome un `string` y retorne la cantidad de vocales que esta contiene. \ No newline at end of file diff --git a/exercises/04-VowelCount/README.md b/exercises/04-VowelCount/README.md new file mode 100644 index 0000000..2afde21 --- /dev/null +++ b/exercises/04-VowelCount/README.md @@ -0,0 +1,4 @@ +# `04` Vowel Counter + +## Instructions 🗒 +1. Create a function that takes a `string` and returns the number of vowels contained within it. \ No newline at end of file diff --git a/exercises/04-VowelCount/app.js b/exercises/04-VowelCount/app.js new file mode 100644 index 0000000..851493a --- /dev/null +++ b/exercises/04-VowelCount/app.js @@ -0,0 +1 @@ +// your code here \ No newline at end of file diff --git a/exercises/04-VowelCount/solution.hide.js b/exercises/04-VowelCount/solution.hide.js new file mode 100644 index 0000000..d26d142 --- /dev/null +++ b/exercises/04-VowelCount/solution.hide.js @@ -0,0 +1,5 @@ +// your code here +function findVowels(word) { + const matched = word.match(/[aeiou]/gi); + return matched ? matched.length : 0; +} \ No newline at end of file diff --git a/exercises/04-VowelCount/test.js b/exercises/04-VowelCount/test.js new file mode 100644 index 0000000..7618d7f --- /dev/null +++ b/exercises/04-VowelCount/test.js @@ -0,0 +1,15 @@ +const rewire = require("rewire") +const app = rewire('./app.js') + + +test('findVowels function must exist.', ()=>{ + const findVowels = app.__get__('findVowels') + expect(findVowels).toBeTruthy(); +}) + +test('You must have the correct number of vowels', ()=>{ + const findVowels = app.__get__("findVowels"); + + expect(findVowels("carola")).toBe(3) + expect(findVowels("youtube")).toBe(4) +}) \ No newline at end of file diff --git a/exercises/05-DateTime/README.es.md b/exercises/05-DateTime/README.es.md new file mode 100644 index 0000000..9569453 --- /dev/null +++ b/exercises/05-DateTime/README.es.md @@ -0,0 +1,6 @@ +# `05` Date and Time + +## Instrucciones 🗒 +1. Imprima la fecha y la hora actuales en el formato predeterminado. Asigne el resultado final a una variable `today`. +2. Imprima la fecha y hora actual en estilo localizado. Asigne el resultado final a unas variables `date` y `time`. +3. Imprima la fecha y hora actuales con un patrón. Asigne el resultado final a una variable `dateTime`. \ No newline at end of file diff --git a/exercises/05-DateTime/README.md b/exercises/05-DateTime/README.md new file mode 100644 index 0000000..d291b83 --- /dev/null +++ b/exercises/05-DateTime/README.md @@ -0,0 +1,7 @@ +# `05` Date and Time + +## Instructions 🗒 +1. Print the current date and time in default format. Assign the final result to a `today` variable. +2. Print the current date and time in localised style. Assign the final result to a `date` and `time` variabales. +3. Print the current date and time with a pattern. Assign the final result to a `dateTime` variable. + diff --git a/exercises/05-DateTime/app.js b/exercises/05-DateTime/app.js new file mode 100644 index 0000000..851493a --- /dev/null +++ b/exercises/05-DateTime/app.js @@ -0,0 +1 @@ +// your code here \ No newline at end of file diff --git a/exercises/05-DateTime/solution.hide.js b/exercises/05-DateTime/solution.hide.js new file mode 100644 index 0000000..c5eb422 --- /dev/null +++ b/exercises/05-DateTime/solution.hide.js @@ -0,0 +1,7 @@ +const today = new Date(); +const date = + today.getFullYear() + "-" + (today.getMonth() + 1) + "-" + today.getDate(); +const time = + today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds(); +const dateTime = date + " " + time; +console.log(dateTime); diff --git a/exercises/05-DateTime/test.js b/exercises/05-DateTime/test.js new file mode 100644 index 0000000..ceaa34c --- /dev/null +++ b/exercises/05-DateTime/test.js @@ -0,0 +1,24 @@ +const rewire = require("rewire"); +const app = rewire("./app.js"); + +test("today variable must exist.", () => { + const today = app.__get__("today"); + expect(today).toBeTruthy(); +}); +test("date variable must exist.", () => { + const date = app.__get__("date"); + expect(date).toBeTruthy(); +}); +test("time variable must exist.", () => { + const time = app.__get__("time"); + expect(time).toBeTruthy(); +}); +test("dateTime variable must exist.", () => { + const dateTime = app.__get__("dateTime"); + expect(dateTime).toBeTruthy(); +}); +test("today must be a date object", () => { + const today = app.__get__("today"); + expect(typeof today).toBe("object"); +}); + diff --git a/exercises/06-DivisibleBy5/README.es.md b/exercises/06-DivisibleBy5/README.es.md new file mode 100644 index 0000000..fb38dba --- /dev/null +++ b/exercises/06-DivisibleBy5/README.es.md @@ -0,0 +1,4 @@ +# `06` Divisible By 5 + +## Instrucciones 🗒 +1. Crea una función que retorne `true` si un integral es divisible por `5`, y `false` si no lo es. \ No newline at end of file diff --git a/exercises/06-DivisibleBy5/README.md b/exercises/06-DivisibleBy5/README.md new file mode 100644 index 0000000..5b02337 --- /dev/null +++ b/exercises/06-DivisibleBy5/README.md @@ -0,0 +1,4 @@ +# `06` Divisible By 5 + +## Instructions 🗒 +1. Create a function that returns `true` if an integer is divisible by `5`, and `false` otherwise. \ No newline at end of file diff --git a/exercises/06-DivisibleBy5/app.js b/exercises/06-DivisibleBy5/app.js new file mode 100644 index 0000000..851493a --- /dev/null +++ b/exercises/06-DivisibleBy5/app.js @@ -0,0 +1 @@ +// your code here \ No newline at end of file diff --git a/exercises/06-DivisibleBy5/solution.hide.js b/exercises/06-DivisibleBy5/solution.hide.js new file mode 100644 index 0000000..d3029b7 --- /dev/null +++ b/exercises/06-DivisibleBy5/solution.hide.js @@ -0,0 +1,4 @@ +// your code here + function divisibleBy5(int) { + return int % 5 === 0 ? true : false; + } \ No newline at end of file diff --git a/exercises/06-DivisibleBy5/test.js b/exercises/06-DivisibleBy5/test.js new file mode 100644 index 0000000..cf8b539 --- /dev/null +++ b/exercises/06-DivisibleBy5/test.js @@ -0,0 +1,19 @@ +const rewire = require("rewire"); +const app = rewire("./app.js"); + +test("Function divisibleBy5 should exist", () => { + const divisibleBy5 = app.__get__("divisibleBy5"); + expect(divisibleBy5).toBeTruthy(); +}); +test("Number should be divisible by 5", () => { + const divisibleBy5 = app.__get__("divisibleBy5"); + //checks if true when divisible by 5 + expect(divisibleBy5(35)).toBe(true); + expect(divisibleBy5(30)).toBe(true); + expect(divisibleBy5(5)).toBe(true); + expect(divisibleBy5(90)).toBe(true); + + // Checks if false when not divisible by 5 + expect(divisibleBy5(14)).toBe(false); + expect(divisibleBy5(26)).toBe(false); +}); diff --git a/exercises/07-Factorial/README.es.md b/exercises/07-Factorial/README.es.md new file mode 100644 index 0000000..418b8c6 --- /dev/null +++ b/exercises/07-Factorial/README.es.md @@ -0,0 +1,9 @@ +# `07` Factorial + +## Instrucciones 🗒 +1. Este desafío requiere que devuelvas el factorial de un número dado. +2. Un factorial de un número (`num`), es num multiplicado por (`num-1`) multiplicado por (`num-2`) y así sucesivamente hasta llegar al número 1. +3. Debe haber una funcion llamada `factorialize`. + +## Ejemplo 💡 +El factorial de `4` es `4 * 3 * 2 * 1 = 24`. Pasa de `1` a `num`, multiplicando cada número por el anterior, hasta llegar al número. \ No newline at end of file diff --git a/exercises/07-Factorial/README.md b/exercises/07-Factorial/README.md new file mode 100644 index 0000000..ce7da64 --- /dev/null +++ b/exercises/07-Factorial/README.md @@ -0,0 +1,9 @@ +# `07` Factorial + +## Instructions 🗒 +1. This challenge requires you to return the factorial of a given number. +2. A factorial of a number (`num`), is num multiplied by (`num-1`) multiplied by (`num-2`) and so forth until you reach the number 1. +3. There must be a `factorialize` function. + +## Example 💡 +The factorial of `4` is `4 * 3 * 2 * 1 = 24`. Loop from `1` to `num`, multiplying each number by the previous one, until you reach the number. \ No newline at end of file diff --git a/exercises/07-Factorial/app.js b/exercises/07-Factorial/app.js new file mode 100644 index 0000000..851493a --- /dev/null +++ b/exercises/07-Factorial/app.js @@ -0,0 +1 @@ +// your code here \ No newline at end of file diff --git a/exercises/07-Factorial/solution.hide.js b/exercises/07-Factorial/solution.hide.js new file mode 100644 index 0000000..6c778d2 --- /dev/null +++ b/exercises/07-Factorial/solution.hide.js @@ -0,0 +1,12 @@ +function factorialize(num) { + // Step 1. Create a variable called result to store num + let result = num; + // If num = 0 OR num = 1, the factorial will return 1 + if (num === 0 || num === 1) return 1; + // Step 2. Create the WHILE loop + while (num > 1) { + num--; // decrements by 1 at each iteration + result *= num; + } + return result; +} diff --git a/exercises/07-Factorial/test.js b/exercises/07-Factorial/test.js new file mode 100644 index 0000000..027a5f6 --- /dev/null +++ b/exercises/07-Factorial/test.js @@ -0,0 +1,15 @@ +const rewire = require("rewire"); +const app = rewire("./app.js"); + +test("factorialize function must exist.", () => { + const factorialize = app.__get__("factorialize"); + expect(factorialize).toBeTruthy(); +}); + +test("The factorials yield the correct answer.", () => { + const factorialize = app.__get__("factorialize"); + + expect(factorialize(4)).toBe(24); + expect(factorialize(5)).toBe(120); + expect(factorialize(13)).toBe(6227020800); +}); diff --git a/exercises/08-Fibonacci/README.es.md b/exercises/08-Fibonacci/README.es.md new file mode 100644 index 0000000..b7f803e --- /dev/null +++ b/exercises/08-Fibonacci/README.es.md @@ -0,0 +1,5 @@ +# `08` Fibonacci +La secuencia de Fibonacci es una secuencia de números cuya suma es los dos números anteriores (por ejemplo, 0, 1, 1, 2, 3, etc.). + +## Instrucciones 🗒 +1. Usando `0` y `1` como valores iniciales, cree una función `fib` que imprima y retorna un array que contenga `n` numeros de la secuencia de Fibonacci. \ No newline at end of file diff --git a/exercises/08-Fibonacci/README.md b/exercises/08-Fibonacci/README.md new file mode 100644 index 0000000..5bf3f80 --- /dev/null +++ b/exercises/08-Fibonacci/README.md @@ -0,0 +1,5 @@ +# `08` Fibonacci +The Fibonacci Sequence is a sequence of numbers whose sum is the two preceding numbers (e.g. 0, 1, 1, 2, 3, etc). + +## Instructions 🗒 +1. Using `0` and `1` as the starting values, create a function `fib` that prints and returns an array containing `n` numbers of the Fibonacci sequence. \ No newline at end of file diff --git a/exercises/08-Fibonacci/app.js b/exercises/08-Fibonacci/app.js new file mode 100644 index 0000000..851493a --- /dev/null +++ b/exercises/08-Fibonacci/app.js @@ -0,0 +1 @@ +// your code here \ No newline at end of file diff --git a/exercises/08-Fibonacci/solution.hide.js b/exercises/08-Fibonacci/solution.hide.js new file mode 100644 index 0000000..51fac8c --- /dev/null +++ b/exercises/08-Fibonacci/solution.hide.js @@ -0,0 +1,10 @@ +function fib(n) { + const result = [0, 1]; + for (let i = 2; i < n; i++) { + result.push(result[i - 2] + result[i - 1]); + } + console.log(result.length); + return result; +} + +fib(22) \ No newline at end of file diff --git a/exercises/08-Fibonacci/test.js b/exercises/08-Fibonacci/test.js new file mode 100644 index 0000000..d153e2f --- /dev/null +++ b/exercises/08-Fibonacci/test.js @@ -0,0 +1,17 @@ +const rewire = require("rewire"); +const app = rewire("./app.js"); + +test("fib function must exist.", () => { + const fib = app.__get__("fib"); + expect(fib).toBeTruthy(); +}); +test("fib function must return n amount of Fibonacci numbers.", () => { + const fib = app.__get__("fib"); + expect(fib(22)).toEqual([ + 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, + 2584, 4181, 6765, 10946 + ]); + expect(fib(22).length).toBe(22); + expect(fib(14)).toEqual([0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233]); + expect(fib(14).length).toBe(14); +}); \ No newline at end of file diff --git a/exercises/09-FizzBuzz/README.es.md b/exercises/09-FizzBuzz/README.es.md new file mode 100644 index 0000000..a122da3 --- /dev/null +++ b/exercises/09-FizzBuzz/README.es.md @@ -0,0 +1,7 @@ +# `09` FizzBuzz +Escriba un programa que imprima los números del 1 al 100. + +## Instrucciones 🗒 +1. Para múltiplos de tres, escriba `“Fizz”` en lugar del número. +2. Para los múltiplos de cinco, escribe `“Buzz”`. +3. Para números que son múltiplos de tres y cinco, escriba `“FizzBuzz”`. \ No newline at end of file diff --git a/exercises/09-FizzBuzz/README.md b/exercises/09-FizzBuzz/README.md new file mode 100644 index 0000000..d8d54c5 --- /dev/null +++ b/exercises/09-FizzBuzz/README.md @@ -0,0 +1,7 @@ +# `09` FizzBuzz +Write a program that prints the numbers from 1 to 100. + +## Instructions 🗒 +1. For multiples of three print `“Fizz”` instead of the number. +2. For the multiples of five print `“Buzz”`. +3. For numbers which are multiples of both three and five print `“FizzBuzz”`. \ No newline at end of file diff --git a/exercises/09-FizzBuzz/app.js b/exercises/09-FizzBuzz/app.js new file mode 100644 index 0000000..851493a --- /dev/null +++ b/exercises/09-FizzBuzz/app.js @@ -0,0 +1 @@ +// your code here \ No newline at end of file diff --git a/exercises/09-FizzBuzz/solution.hide.js b/exercises/09-FizzBuzz/solution.hide.js new file mode 100644 index 0000000..74a112b --- /dev/null +++ b/exercises/09-FizzBuzz/solution.hide.js @@ -0,0 +1,11 @@ +for (let i = 0; i < 101; i++) { + if (i % 3 === 0 && i % 5 === 0) { + console.log("FizzBuzz"); + } else if (i % 3 === 0) { + console.log("Fizz"); + } else if (i % 5 === 0) { + console.log("Buzz"); + } else { + console.log(i); + } +} \ No newline at end of file diff --git a/exercises/09-FizzBuzz/test.js b/exercises/09-FizzBuzz/test.js new file mode 100644 index 0000000..43c177c --- /dev/null +++ b/exercises/09-FizzBuzz/test.js @@ -0,0 +1,128 @@ +const fs = require("fs"); +const path = require("path"); + +jest.dontMock("fs"); +//here we are going to store and accumulate (concatenate) all the console log's from the exercise +let _buffer = ""; +let _log = console.log; + +// lets override the console.log function to mock it, +// but we are also going to save what supposed to be the ouput of the console inside _buffer +global.console.log = console.log = jest.fn((text) => (_buffer += text + "\n")); + +test("Your output should be printing, fizz, buzz, fizzbuzz, or just a number depending on whether that number is divisible by 3, 5, 3 & 5, or none", function () { + /* + Here is how to mock the alert function: + https://stackoverflow.com/questions/41885841/how-to-mock-the-javascript-window-object-using-jest + */ + + //then I import the index.js (which should have the alert() call inside) + const file = require("./app.js"); + + //and I expect the console.log to be already called just one time. + expect(console.log.mock.calls.length).toBe(101); + + //You can also compare the entire console buffer (if there have been several console.log calls on the exercise) + expect(_buffer).toBe( +`FizzBuzz +1 +2 +Fizz +4 +Buzz +Fizz +7 +8 +Fizz +Buzz +11 +Fizz +13 +14 +FizzBuzz +16 +17 +Fizz +19 +Buzz +Fizz +22 +23 +Fizz +Buzz +26 +Fizz +28 +29 +FizzBuzz +31 +32 +Fizz +34 +Buzz +Fizz +37 +38 +Fizz +Buzz +41 +Fizz +43 +44 +FizzBuzz +46 +47 +Fizz +49 +Buzz +Fizz +52 +53 +Fizz +Buzz +56 +Fizz +58 +59 +FizzBuzz +61 +62 +Fizz +64 +Buzz +Fizz +67 +68 +Fizz +Buzz +71 +Fizz +73 +74 +FizzBuzz +76 +77 +Fizz +79 +Buzz +Fizz +82 +83 +Fizz +Buzz +86 +Fizz +88 +89 +FizzBuzz +91 +92 +Fizz +94 +Buzz +Fizz +97 +98 +Fizz +Buzz\n`); +}); diff --git a/exercises/10-CapitaliseLetters/README.es.md b/exercises/10-CapitaliseLetters/README.es.md new file mode 100644 index 0000000..b1f6147 --- /dev/null +++ b/exercises/10-CapitaliseLetters/README.es.md @@ -0,0 +1,5 @@ +# `10` Capitalise Letters + +## Instrucciones 🗒 +1. Cree una función `caps` que convierta el primer carácter de cada palabra en mayúsculas. +2. Imprima y retorne la palabra o frase recién formateado. \ No newline at end of file diff --git a/exercises/10-CapitaliseLetters/README.md b/exercises/10-CapitaliseLetters/README.md new file mode 100644 index 0000000..3a6c3cc --- /dev/null +++ b/exercises/10-CapitaliseLetters/README.md @@ -0,0 +1,5 @@ +# `10` Capitalise Letters + +## Instructions 🗒 +1. Create a function `caps` that converts the first character of each word to uppercase. +2. Print and return the newly formatted string. \ No newline at end of file diff --git a/exercises/10-CapitaliseLetters/app.js b/exercises/10-CapitaliseLetters/app.js new file mode 100644 index 0000000..851493a --- /dev/null +++ b/exercises/10-CapitaliseLetters/app.js @@ -0,0 +1 @@ +// your code here \ No newline at end of file diff --git a/exercises/10-CapitaliseLetters/solution.hide.js b/exercises/10-CapitaliseLetters/solution.hide.js new file mode 100644 index 0000000..6e21d70 --- /dev/null +++ b/exercises/10-CapitaliseLetters/solution.hide.js @@ -0,0 +1,10 @@ +const caps = (str) => { + str = str + .toLowerCase() + .split(" ") + .map((s) => s.charAt(0).toUpperCase() + s.substring(1)) + .join(" "); + console.log(str); + return str; +}; +caps("javascript is a fantastic language."); diff --git a/exercises/10-CapitaliseLetters/test.js b/exercises/10-CapitaliseLetters/test.js new file mode 100644 index 0000000..57d79b9 --- /dev/null +++ b/exercises/10-CapitaliseLetters/test.js @@ -0,0 +1,39 @@ +const fs = require("fs"); +const path = require("path"); + +jest.dontMock("fs"); +//here we are going to store and accumulate (concatenate) all the console log's from the exercise +let _buffer = ""; +let _log = console.log; + +// lets override the console.log function to mock it, +// but we are also going to save what supposed to be the ouput of the console inside _buffer +global.console.log = console.log = jest.fn((text) => (_buffer += text + "\n")); + +test("You should be printing your result", function () { + /* + Here is how to mock the alert function: + https://stackoverflow.com/questions/41885841/how-to-mock-the-javascript-window-object-using-jest + */ + + //then I import the index.js (which should have the alert() call inside) + const file = require("./app.js"); + + //and I expect the console.log to be already called just one time. + expect(console.log.mock.calls.length).toBe(1); +}); + + +const rewire = require("rewire"); +const app = rewire("./app.js"); + +test("caps function must exist", ()=>{ + const caps = app.__get__("caps"); + expect(caps).toBeTruthy(); +}) +test("caps function must return strings in the correct format for any input", ()=>{ + const caps = app.__get__("caps"); + expect(caps("the world of gamble")).toBe("The World Of Gamble") + expect(caps("My little Angel")).toBe("My Little Angel") + expect(caps("jose Alberto hernandez cortez de borbon")).toBe("Jose Alberto Hernandez Cortez De Borbon") +}) \ No newline at end of file diff --git a/exercises/11-MultiplyAndSkip/README.es.md b/exercises/11-MultiplyAndSkip/README.es.md new file mode 100644 index 0000000..5cec343 --- /dev/null +++ b/exercises/11-MultiplyAndSkip/README.es.md @@ -0,0 +1,4 @@ +# `11` Multiply and Skip + +## Instrucciones 🗒 +1. Itera del 1 al 100 inclusivo y imprime los múltiplos de `5` mientras **saltas** los múltiplos de `3`. \ No newline at end of file diff --git a/exercises/11-MultiplyAndSkip/README.md b/exercises/11-MultiplyAndSkip/README.md new file mode 100644 index 0000000..e5a5459 --- /dev/null +++ b/exercises/11-MultiplyAndSkip/README.md @@ -0,0 +1,4 @@ +# `11` Multiply and Skip + +## Instructions 🗒 +1. Iterate from 1 to 100 inclusive and print the multiples of `5` whilst **skipping** the multiples of `3`. \ No newline at end of file diff --git a/exercises/11-MultiplyAndSkip/app.js b/exercises/11-MultiplyAndSkip/app.js new file mode 100644 index 0000000..851493a --- /dev/null +++ b/exercises/11-MultiplyAndSkip/app.js @@ -0,0 +1 @@ +// your code here \ No newline at end of file diff --git a/exercises/11-MultiplyAndSkip/solution.hide.js b/exercises/11-MultiplyAndSkip/solution.hide.js new file mode 100644 index 0000000..b7a38a8 --- /dev/null +++ b/exercises/11-MultiplyAndSkip/solution.hide.js @@ -0,0 +1,7 @@ +for (let i = 1; i <= 100; i++) { + if (i % 3 === 0) { + continue; + } else if (i % 5 === 0) { + console.log(i); + } +} \ No newline at end of file diff --git a/exercises/11-MultiplyAndSkip/test.js b/exercises/11-MultiplyAndSkip/test.js new file mode 100644 index 0000000..dba5022 --- /dev/null +++ b/exercises/11-MultiplyAndSkip/test.js @@ -0,0 +1,42 @@ +const fs = require("fs"); +const path = require("path"); + +jest.dontMock("fs"); +//here we are going to store and accumulate (concatenate) all the console log's from the exercise +let _buffer = ""; +let _log = console.log; + +// lets override the console.log function to mock it, +// but we are also going to save what supposed to be the ouput of the console inside _buffer +global.console.log = console.log = jest.fn((text) => (_buffer += text + "\n")); + +test("Your output should be printing, fizz, buzz, fizzbuzz, or just a number depending on whether that number is divisible by 3, 5, 3 & 5, or none", function () { + /* + Here is how to mock the alert function: + https://stackoverflow.com/questions/41885841/how-to-mock-the-javascript-window-object-using-jest + */ + + //then I import the index.js (which should have the alert() call inside) + const file = require("./app.js"); + + //and I expect the console.log to be already called just one time. + expect(console.log.mock.calls.length).toBe(14); + + //You can also compare the entire console buffer (if there have been several console.log calls on the exercise) + expect(_buffer).toBe( +`5 +10 +20 +25 +35 +40 +50 +55 +65 +70 +80 +85 +95 +100\n` + ); +}); diff --git a/exercises/12-NameChange/README.es.md b/exercises/12-NameChange/README.es.md new file mode 100644 index 0000000..fecaf0f --- /dev/null +++ b/exercises/12-NameChange/README.es.md @@ -0,0 +1,4 @@ +# `12` Name Change + +## Instrucciones 🗒 +1. Cambia tu apellido usando una función constructora `Person`, la función `changeName` y una instancia de `objeto`. \ No newline at end of file diff --git a/exercises/12-NameChange/README.md b/exercises/12-NameChange/README.md new file mode 100644 index 0000000..d578df5 --- /dev/null +++ b/exercises/12-NameChange/README.md @@ -0,0 +1,4 @@ +# `12` Name Change + +## Instructions 🗒 +1. Change your surname using a constructor function `Person`, the `changeName` function and an `object` instance. \ No newline at end of file diff --git a/exercises/12-NameChange/app.js b/exercises/12-NameChange/app.js new file mode 100644 index 0000000..851493a --- /dev/null +++ b/exercises/12-NameChange/app.js @@ -0,0 +1 @@ +// your code here \ No newline at end of file diff --git a/exercises/12-NameChange/solution.hide.js b/exercises/12-NameChange/solution.hide.js new file mode 100644 index 0000000..646d630 --- /dev/null +++ b/exercises/12-NameChange/solution.hide.js @@ -0,0 +1,20 @@ +// your code here +function Person(firstName, lastName) { + this.firstName = firstName; + this.lastName = lastName; + // change name function + this.changeName = function (name) { + this.lastName = name; + }; +} + +// Object instance +const person1 = new Person("Sharon", "Goldsworth"); + +// changeName() changes last name +person1.changeName("Smith"); + +// Print new name +console.log( + `Person one is now called ${person1.firstName} ${person1.lastName}.` +); diff --git a/exercises/12-NameChange/test.js b/exercises/12-NameChange/test.js new file mode 100644 index 0000000..243420e --- /dev/null +++ b/exercises/12-NameChange/test.js @@ -0,0 +1,20 @@ +const rewire = require("rewire"); +const app = rewire("./app.js"); +const Person = app.__get__("Person"); +const person1 = new Person("John", "Calleway") + +test("Person object function must exist", () => { + expect(Person).toBeTruthy(); +}); +test("firstName property must exist in Person object", () => { + expect(person1.firstName).toBe("John"); +}); +test("lastName property must exist in Person object", () => { + expect(person1.lastName).toBe("Calleway"); +}); + +test("I should be able to change my last name.", () => { + person1.changeName("Lucas") + + expect(person1.lastName).toBe("Lucas"); +}) diff --git a/exercises/13-Palindrome/README.es.md b/exercises/13-Palindrome/README.es.md new file mode 100644 index 0000000..0c3f897 --- /dev/null +++ b/exercises/13-Palindrome/README.es.md @@ -0,0 +1,6 @@ +# `13` Palindrome +Un palíndromo es una palabra, número u otra secuencia de caracteres que se lee igual hacia atrás que hacia adelante, como "Ana" o "Otto". También puede crear un palíndromo int. + +## Instrucciones 🗒 +1. Dada una cadena de texto, devuelva `true` o `false` indicando si el texto es un palíndromo o no. +2. Debe haber una funcion llamada `palindrome`. \ No newline at end of file diff --git a/exercises/13-Palindrome/README.md b/exercises/13-Palindrome/README.md new file mode 100644 index 0000000..bd39eee --- /dev/null +++ b/exercises/13-Palindrome/README.md @@ -0,0 +1,6 @@ +# `13` Palindrome +A palindrome is a word, number, or other sequence of characters which reads the same backward as forward, such as "madam" or "racecar". You can also create an int palindrome. + +## Instructions 🗒 +1. Given a string of text, return `true` or `false` indicating whether or not the text is a palindrome. +2. There should be a function called `palindrome`. \ No newline at end of file diff --git a/exercises/13-Palindrome/app.js b/exercises/13-Palindrome/app.js new file mode 100644 index 0000000..851493a --- /dev/null +++ b/exercises/13-Palindrome/app.js @@ -0,0 +1 @@ +// your code here \ No newline at end of file diff --git a/exercises/13-Palindrome/solution.hide.js b/exercises/13-Palindrome/solution.hide.js new file mode 100644 index 0000000..3cb43d1 --- /dev/null +++ b/exercises/13-Palindrome/solution.hide.js @@ -0,0 +1,8 @@ +const palindrome = (str) => { + // turn string to lowercase + str = str.toLowerCase(); + // split, reverse & join string and print + console.log(str === str.split("").reverse().join("")); + return(str === str.split("").reverse().join("")); +}; +palindrome("anna"); diff --git a/exercises/13-Palindrome/test.js b/exercises/13-Palindrome/test.js new file mode 100644 index 0000000..a4af24d --- /dev/null +++ b/exercises/13-Palindrome/test.js @@ -0,0 +1,16 @@ +const rewire = require("rewire"); +const app = rewire("./app.js"); + +test("palindrome function must exist", () => { + const palindrome = app.__get__("palindrome"); + expect(palindrome).toBeTruthy(); +}); + +test("The function should return if the string is a palidrone or not (true or false)", () => { + const palindrome = app.__get__("palindrome"); + expect(palindrome("anna")).toBe(true); + expect(palindrome("otto")).toBe(true); + expect(palindrome("12321")).toBe(true); + expect(palindrome("madman")).toBe(false); + expect(palindrome("ily")).toBe(false); +}) \ No newline at end of file diff --git a/exercises/14-RemoveCharacters/README.es.md b/exercises/14-RemoveCharacters/README.es.md new file mode 100644 index 0000000..5970ab7 --- /dev/null +++ b/exercises/14-RemoveCharacters/README.es.md @@ -0,0 +1,5 @@ +# `14` Remove Characters + +## Instrucciones 🗒 +1. Cree una funcion `removeChars` que elimine el primer y el último carácter de un string. +2. Retorne el string modificado. \ No newline at end of file diff --git a/exercises/14-RemoveCharacters/README.md b/exercises/14-RemoveCharacters/README.md new file mode 100644 index 0000000..fd97527 --- /dev/null +++ b/exercises/14-RemoveCharacters/README.md @@ -0,0 +1,5 @@ +# `14` Remove Characters + +## Instructions 🗒 +1. Create a function `removeChars` that removes the first and last characters from a string. +2. Return the modified string. \ No newline at end of file diff --git a/exercises/14-RemoveCharacters/app.js b/exercises/14-RemoveCharacters/app.js new file mode 100644 index 0000000..851493a --- /dev/null +++ b/exercises/14-RemoveCharacters/app.js @@ -0,0 +1 @@ +// your code here \ No newline at end of file diff --git a/exercises/14-RemoveCharacters/solution.hide.js b/exercises/14-RemoveCharacters/solution.hide.js new file mode 100644 index 0000000..ef602eb --- /dev/null +++ b/exercises/14-RemoveCharacters/solution.hide.js @@ -0,0 +1,5 @@ +function removeChars(str) { + const result = str.substring(1, str.length - 1); + return result; +} +removeChars("The first and last characters are removed"); diff --git a/exercises/14-RemoveCharacters/test.js b/exercises/14-RemoveCharacters/test.js new file mode 100644 index 0000000..19cdbe2 --- /dev/null +++ b/exercises/14-RemoveCharacters/test.js @@ -0,0 +1,20 @@ +const rewire = require("rewire"); +const app = rewire("./app.js"); + +test("removeChars function must exist", () => { + const removeChars = app.__get__("removeChars"); + expect(removeChars).toBeTruthy(); +}); + +test("The function should return a string with the first and last characters remvoed", () => { + const removeChars = app.__get__("removeChars"); + expect(removeChars("the world of gamble")).toBe("he world of gambl"); + expect(removeChars("hello world")).toBe("ello worl"); + expect( + removeChars( + "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum" + ) + ).toBe( + "orem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laboru" + ); +}); \ No newline at end of file diff --git a/exercises/15-ShareCake/README.es.md b/exercises/15-ShareCake/README.es.md new file mode 100644 index 0000000..6acc6db --- /dev/null +++ b/exercises/15-ShareCake/README.es.md @@ -0,0 +1,6 @@ +# `15` Share the Cake + +## Instrucciones 🗒 +1. Cree una función `sliceOfCake` que determine si es posible o no compartir el pastel de manera justa dados estos tres parámetros: `Total de rebanadas`, `Destinatarios`, `Rebanadas` cada uno. +2. Está bien no usar todo el pastel. +3. Retorne `true` si el pastel se puede compartir por igual; de lo contrario, retorne `false`. \ No newline at end of file diff --git a/exercises/15-ShareCake/README.md b/exercises/15-ShareCake/README.md new file mode 100644 index 0000000..a854ae8 --- /dev/null +++ b/exercises/15-ShareCake/README.md @@ -0,0 +1,6 @@ +# `15` Share the Cake + +## Instructions 🗒 +1. Create a function `sliceOfCake`that determines whether or not it's possible to share the cake fairly given these three parameters: `Total slices`, `Recipients`, `Slices` each. +2. It's fine not to use the entire cake. +3. Print `true` if the cake can be shared equally, otherwise print `false`. \ No newline at end of file diff --git a/exercises/15-ShareCake/app.js b/exercises/15-ShareCake/app.js new file mode 100644 index 0000000..851493a --- /dev/null +++ b/exercises/15-ShareCake/app.js @@ -0,0 +1 @@ +// your code here \ No newline at end of file diff --git a/exercises/15-ShareCake/solution.hide.js b/exercises/15-ShareCake/solution.hide.js new file mode 100644 index 0000000..23e80ee --- /dev/null +++ b/exercises/15-ShareCake/solution.hide.js @@ -0,0 +1,5 @@ +// your code here +const sliceOfCake = (totalSlices, recipients, slicesPerPerson) => { + const result = recipients * slicesPerPerson < totalSlices ? true : false; + return result; +}; diff --git a/exercises/15-ShareCake/test.js b/exercises/15-ShareCake/test.js new file mode 100644 index 0000000..ac3f34d --- /dev/null +++ b/exercises/15-ShareCake/test.js @@ -0,0 +1,15 @@ +const rewire = require("rewire"); +const app = rewire("./app.js"); + +test("sliceOfCake function must exist.", () => { + const sliceOfCake = app.__get__("sliceOfCake"); + expect(sliceOfCake).toBeTruthy(); +}); + +test("Phone number must be formatted correctly.", () => { + const sliceOfCake = app.__get__("sliceOfCake"); + + expect(sliceOfCake(20, 5, 1)).toBe(true); + expect(sliceOfCake(64, 17, 10)).toBe(false); + expect(sliceOfCake(400, 45, 3)).toBe(true); +}); \ No newline at end of file diff --git a/exercises/16-FormatPhoneNumber/README.es.md b/exercises/16-FormatPhoneNumber/README.es.md new file mode 100644 index 0000000..9081015 --- /dev/null +++ b/exercises/16-FormatPhoneNumber/README.es.md @@ -0,0 +1,8 @@ +# `16` Format Phone Number + +## Instrucciones 🗒 +1. Cree una función `formatPhoneNumber` que tome un array de `10` números entre `0` y `9` y `retorne` una cadena de números formateados como un número de teléfono. +2. La llamada de la función debería parecerse a algo como esto: +``` JavaScript +formatPhoneNumber(4, 4, 1, 2, 3, 4, 5, 6, 7, 8) +``` \ No newline at end of file diff --git a/exercises/16-FormatPhoneNumber/README.md b/exercises/16-FormatPhoneNumber/README.md new file mode 100644 index 0000000..82627da --- /dev/null +++ b/exercises/16-FormatPhoneNumber/README.md @@ -0,0 +1,8 @@ +# `16` Format Phone Number + +## Instructions 🗒 +1. Create a function `formatPhoneNumber` that takes an array of `10` numbers between `0` and `9`and `returns` a string of numbers formatted as a phone number. +2. The function call should resemble something like this: +```JavaScript +formatPhoneNumber(4, 4, 1, 2, 3, 4, 5, 6, 7, 8) +``` \ No newline at end of file diff --git a/exercises/16-FormatPhoneNumber/app.js b/exercises/16-FormatPhoneNumber/app.js new file mode 100644 index 0000000..851493a --- /dev/null +++ b/exercises/16-FormatPhoneNumber/app.js @@ -0,0 +1 @@ +// your code here \ No newline at end of file diff --git a/exercises/16-FormatPhoneNumber/solution.hide.js b/exercises/16-FormatPhoneNumber/solution.hide.js new file mode 100644 index 0000000..fb019b9 --- /dev/null +++ b/exercises/16-FormatPhoneNumber/solution.hide.js @@ -0,0 +1,8 @@ +// your code here +function formatPhoneNumber(numbers) { + const args = Array.prototype.slice.call(arguments); + args.splice(6, 0, "-"); + args.splice(3, 0, ") "); + args.splice(0, 0, "("); + return args.join(""); +} diff --git a/exercises/16-FormatPhoneNumber/test.js b/exercises/16-FormatPhoneNumber/test.js new file mode 100644 index 0000000..f5cf72b --- /dev/null +++ b/exercises/16-FormatPhoneNumber/test.js @@ -0,0 +1,15 @@ +const rewire = require("rewire"); +const app = rewire("./app.js"); + +test("formatPhoneNumber function must exist.", () => { + const formatPhoneNumber = app.__get__("formatPhoneNumber"); + expect(formatPhoneNumber).toBeTruthy(); +}); + +test("Phone number must be formatted correctly.", () => { + const formatPhoneNumber = app.__get__("formatPhoneNumber"); + + expect(formatPhoneNumber(7,8,6,7,4,0,2,3,1,4)).toBe("(786) 740-2314"); + expect(formatPhoneNumber(5,1,2,4,6,0,0,1,0,4)).toBe("(512) 460-0104"); + expect(formatPhoneNumber(8,8,1,6,2,0,2,5,1,7)).toBe("(881) 620-2517"); +}); diff --git a/exercises/17-AreaOfTriangle/README.es.md b/exercises/17-AreaOfTriangle/README.es.md new file mode 100644 index 0000000..49aec11 --- /dev/null +++ b/exercises/17-AreaOfTriangle/README.es.md @@ -0,0 +1,4 @@ +# `17` Area Of The Triangle + +## Instrucciones 🗒 +1. Escribe una funcion `AreaOfTriangle` que toma la `base` y la `altura` de un triangulo y retorna su `area`. \ No newline at end of file diff --git a/exercises/17-AreaOfTriangle/README.md b/exercises/17-AreaOfTriangle/README.md new file mode 100644 index 0000000..551fe40 --- /dev/null +++ b/exercises/17-AreaOfTriangle/README.md @@ -0,0 +1,4 @@ +# `17` Area Of The Triangle + +## Instructions 🗒 +1. Write a function `AreaOfTriangle` that takes the `base` and `height` of a triangle and print its `area`. \ No newline at end of file diff --git a/exercises/17-AreaOfTriangle/app.js b/exercises/17-AreaOfTriangle/app.js new file mode 100644 index 0000000..851493a --- /dev/null +++ b/exercises/17-AreaOfTriangle/app.js @@ -0,0 +1 @@ +// your code here \ No newline at end of file diff --git a/exercises/17-AreaOfTriangle/solution.hide.js b/exercises/17-AreaOfTriangle/solution.hide.js new file mode 100644 index 0000000..1260e85 --- /dev/null +++ b/exercises/17-AreaOfTriangle/solution.hide.js @@ -0,0 +1,5 @@ +// your code here +function AreaOfTriangle(b, h) { + const result = (b * h) / 2; + return result; +} \ No newline at end of file diff --git a/exercises/17-AreaOfTriangle/test.js b/exercises/17-AreaOfTriangle/test.js new file mode 100644 index 0000000..4db2713 --- /dev/null +++ b/exercises/17-AreaOfTriangle/test.js @@ -0,0 +1,15 @@ +const rewire = require("rewire") +const app = rewire('./app.js') + + +test('AreaOfTriangle function must exist.', ()=>{ + const AreaOfTriangle = app.__get__('AreaOfTriangle') + expect(AreaOfTriangle).toBeTruthy(); +}) + +test('The base for the triangle is correct', ()=>{ + const AreaOfTriangle = app.__get__("AreaOfTriangle"); + + expect(AreaOfTriangle(2,5)).toBe(5) + expect(AreaOfTriangle(7,14)).toBe(49) +}) \ No newline at end of file diff --git a/exercises/18-LongestWord/README.es.md b/exercises/18-LongestWord/README.es.md new file mode 100644 index 0000000..4580e67 --- /dev/null +++ b/exercises/18-LongestWord/README.es.md @@ -0,0 +1,4 @@ +# `18` Longest Word + +## Instrucciones 🗒 +1. Escribe una funcion `longestWord` que toma `(sen)` como un parametro y retorna la palabra más larga en una frase. \ No newline at end of file diff --git a/exercises/18-LongestWord/README.md b/exercises/18-LongestWord/README.md new file mode 100644 index 0000000..587b4ca --- /dev/null +++ b/exercises/18-LongestWord/README.md @@ -0,0 +1,4 @@ +# `18` Longest Word + +## Instructions 🗒 +1. Write a function `longestWord` that takes in `(sen)` as a parameter and returns the longest word in a sentence. \ No newline at end of file diff --git a/exercises/18-LongestWord/app.js b/exercises/18-LongestWord/app.js new file mode 100644 index 0000000..851493a --- /dev/null +++ b/exercises/18-LongestWord/app.js @@ -0,0 +1 @@ +// your code here \ No newline at end of file diff --git a/exercises/18-LongestWord/solution.hide.js b/exercises/18-LongestWord/solution.hide.js new file mode 100644 index 0000000..fbb374d --- /dev/null +++ b/exercises/18-LongestWord/solution.hide.js @@ -0,0 +1,13 @@ +// your code here +function longestWord(sen) { + let str = sen.split(" "); + let longest = 0; + sen = null; + for (let i = 0; i < str.length; i++) { + if (longest < str[i].length) { + longest = str[i].length; + sen = str[i]; + } + } + return sen; +} \ No newline at end of file diff --git a/exercises/18-LongestWord/test.js b/exercises/18-LongestWord/test.js new file mode 100644 index 0000000..9d53d80 --- /dev/null +++ b/exercises/18-LongestWord/test.js @@ -0,0 +1,15 @@ +const rewire = require("rewire") +const app = rewire('./app.js') + + +test('longestWord function must exist.', ()=>{ + const longestWord = app.__get__('longestWord') + expect(longestWord).toBeTruthy(); +}) + +test('You should return the longest word', ()=>{ + const longestWord = app.__get__("longestWord"); + + expect(longestWord("Well, which is the longest word?")).toBe("longest"); + expect(longestWord("Hello my name is Nicola de Fuentevideo")).toBe("Fuentevideo"); +}) \ No newline at end of file diff --git a/exercises/19-MissingAngle/README.es.md b/exercises/19-MissingAngle/README.es.md new file mode 100644 index 0000000..768e725 --- /dev/null +++ b/exercises/19-MissingAngle/README.es.md @@ -0,0 +1,6 @@ +# `19` Missing Angle + +## Instrucciones 🗒 +1. Crea una funcion `missingAngle` que clasifica el angulo faltante como "agudo", "recto", or "obtuso" basado en los grados. +2. Provee dos numeros argumentos. +3. Calcula el angulo faltante sumando los dos numeros y restandolos de 180 grados. \ No newline at end of file diff --git a/exercises/19-MissingAngle/README.md b/exercises/19-MissingAngle/README.md new file mode 100644 index 0000000..38255e6 --- /dev/null +++ b/exercises/19-MissingAngle/README.md @@ -0,0 +1,6 @@ +# `19` Missing Angle + +## Instructions 🗒 +1. Create a function `missingAngle` that classifies the missing angle as either "Acute", "Right", or "Obtuse" based on its degrees. +2. Provide two numbers as arguments. +3. Calculate the missing degree by adding the two numbers and subtracting that from 180. \ No newline at end of file diff --git a/exercises/19-MissingAngle/app.js b/exercises/19-MissingAngle/app.js new file mode 100644 index 0000000..851493a --- /dev/null +++ b/exercises/19-MissingAngle/app.js @@ -0,0 +1 @@ +// your code here \ No newline at end of file diff --git a/exercises/19-MissingAngle/solution.hide.js b/exercises/19-MissingAngle/solution.hide.js new file mode 100644 index 0000000..525cfca --- /dev/null +++ b/exercises/19-MissingAngle/solution.hide.js @@ -0,0 +1,12 @@ +// your code here +const missingAngle = (degree1, degree2) => { + const result = 180 - (degree1 + degree2); + switch (true) { + case result < 90: + return "Acute"; + case result === 90: + return "Right"; + case result >= 90: + return "Obtuse"; + } +}; diff --git a/exercises/19-MissingAngle/test.js b/exercises/19-MissingAngle/test.js new file mode 100644 index 0000000..8f7d825 --- /dev/null +++ b/exercises/19-MissingAngle/test.js @@ -0,0 +1,17 @@ +const rewire = require("rewire") +const app = rewire('./app.js') + + +test('missingAngle function must exist.', ()=>{ + const missingAngle = app.__get__('missingAngle') + expect(missingAngle).toBeTruthy(); +}) + +test('The missing angle is correctly classified.', ()=>{ + const missingAngle = app.__get__("missingAngle"); + + expect(missingAngle(25, 30)).toBe("Obtuse") + expect(missingAngle(17, 71)).toBe("Obtuse") + expect(missingAngle(26, 90)).toBe("Acute") + expect(missingAngle(54, 36)).toBe("Right") +}) \ No newline at end of file diff --git a/exercises/20-NumberLimit/README.es.md b/exercises/20-NumberLimit/README.es.md new file mode 100644 index 0000000..897c563 --- /dev/null +++ b/exercises/20-NumberLimit/README.es.md @@ -0,0 +1,6 @@ +# `20` Number Limit +## Instrucciones 🗒 +1. Escriba una función `numLimit` que tome tres argumentos numéricos (un número como entrada y los otros dos números que representan los puntos más bajo y más alto del rango). +2. Si el número cae dentro del rango, `retorna` el número. +3. Si el número es menor que el límite inferior del rango, `retorna` el número del límite inferior. +4. Si el número es mayor que el límite superior del rango, `retorna` el número del límite más alto. \ No newline at end of file diff --git a/exercises/20-NumberLimit/README.md b/exercises/20-NumberLimit/README.md new file mode 100644 index 0000000..27b3dbc --- /dev/null +++ b/exercises/20-NumberLimit/README.md @@ -0,0 +1,6 @@ +# `20` Number Limit +## Instructions 🗒 +1. Write a function `numLimit` which takes three number arguments (one number as an input and the other two numbers representing the lowest and highest points of the range). +2. If the number falls within the range, `return` the number. +3. If the number is less than the lower limit of the range, `return` the lowest limit number. +4. If the number is greater than the upper limit of the range, `return` the highest limit number. \ No newline at end of file diff --git a/exercises/20-NumberLimit/app.js b/exercises/20-NumberLimit/app.js new file mode 100644 index 0000000..851493a --- /dev/null +++ b/exercises/20-NumberLimit/app.js @@ -0,0 +1 @@ +// your code here \ No newline at end of file diff --git a/exercises/20-NumberLimit/solution.hide.js b/exercises/20-NumberLimit/solution.hide.js new file mode 100644 index 0000000..1b62059 --- /dev/null +++ b/exercises/20-NumberLimit/solution.hide.js @@ -0,0 +1,11 @@ +// your code here +const numLimit = (num, lowest, highest) => { + switch (true) { + case num >= lowest && num <= highest: + return num; + case num < lowest: + return lowest; + case num > highest: + return highest; + } +}; diff --git a/exercises/20-NumberLimit/test.js b/exercises/20-NumberLimit/test.js new file mode 100644 index 0000000..3f8045b --- /dev/null +++ b/exercises/20-NumberLimit/test.js @@ -0,0 +1,17 @@ +const rewire = require("rewire"); +const app = rewire("./app.js"); + +test("numLimit function must exist.", () => { + const numLimit = app.__get__("numLimit"); + expect(numLimit).toBeTruthy(); +}); + +test("The missing angle is correctly classified.", () => { + const numLimit = app.__get__("numLimit"); + + expect(numLimit(25, 30, 50)).toBe(30); + expect(numLimit(17,10, 71)).toBe(17); + expect(numLimit(102, 26, 90)).toBe(90); + expect(numLimit(54, 36, 54)).toBe(54); + expect(numLimit(24, 24, 47)).toBe(24); +}); diff --git a/learn.json b/learn.json new file mode 100644 index 0000000..bda7339 --- /dev/null +++ b/learn.json @@ -0,0 +1,17 @@ +{ + "dirPath": "./.learn", + "configPath": "./learn.json", + "outputPath": "./.learn/dist", + "publicPath": "/preview", + "language": "auto", + "grading": "isolated", + "exercisesPath": "./exercises", + "disableGrading": false, + "disabledActions": [], + "actions": [], + "difficulty": "easy", + "duration": 2, + "description": "20 javascript problems to test your knowledge", + "title": "Javascript 20 Challenges", + "slug": "javascript-20-challenges" +} \ No newline at end of file