Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution #205

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Agrega soluciones a ejercicios y tests
  • Loading branch information
WanCirone authored and atralice committed Jan 5, 2021
commit d0f23eab31560c83464345fb1264abcf4106bb33
28 changes: 28 additions & 0 deletions 07-JS-VI/homework/homework.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
// Do not change any of the function names

function mayuscula(nombre) {
//La función recibe un nombre y debe devolver el mismo que recibe pero con su primer letra en mayúscula
//ej: Recibe "mario" ----> Devuelve "Mario"
return nombre[0].toUpperCase() + nombre.slice(1);
}

function invocarCallback(cb) {
// Invoca al callback `cb`
cb();
}

function operacionMatematica(n1, n2, cb) {
//Vamos a recibir una función que realiza una operación matemática como callback junto con dos números.
//Devolver el callback pasándole como argumentos los números recibidos.
//Tu código:
return cb(n1, n2);
}

function sumarArray(numeros, cb) {
// Suma todos los números enteros (int/integers) de un array ("numeros")
// Pasa el resultado a `cb`
Expand Down Expand Up @@ -53,12 +66,27 @@ function map(array, cb) {
return nuevoArray;
}

function filter(array) {
//Filtrar todos los elementos del array que comiencen con la letra "a".
//Devolver un nuevo array con los elementos que cumplen la condición
var nuevoArray = [];
for(let i = 0; i<array.length; i++) {
if(array[i][0] === "a") {
nuevoArray.push(array[i])
}
}
return nuevoArray;
}

// No modificar nada debajo de esta línea
// --------------------------------

module.exports = {
mayuscula,
invocarCallback,
operacionMatematica,
sumarArray,
forEach,
map,
filter
};
35 changes: 30 additions & 5 deletions 07-JS-VI/homework/tests/JSVI.test.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,37 @@
/* eslint-disable no-undef */
const {
invocarCallback,
sumarArray,
forEach,
map,
mayuscula,
invocarCallback,
operacionMatematica,
sumarArray,
forEach,
map,
filter
} = require('../homework');

describe('mayuscula(nombre)', function() {
it('should return the same name with the first letter capitalized', function() {
expect(mayuscula("mario")).toBe("Mario");
expect(mayuscula("ana")).toBe("Ana");
});
});

describe('invocarCallback(cb)', function() {
it('should invoke the callback that is passed in', function() {
const cb = jest.fn();
invocarCallback(cb);
expect(cb).toHaveBeenCalled();
expect(cb).toHaveBeenCalled();
});
});

describe('operacionMatematica(n1, n2, cb)', function() {
it('should return the callback function passing it the received arguments', function() {
const cb = jest.fn();
operacionMatematica(100, 20, cb);
expect(cb).toHaveBeenCalled();
});
});

describe('sumarArray(cb)', function() {
it('should pass the sum of all array numbers to cb', function(done) {
sumarArray([1, 2, 3, 4, 5], function(sum) {
Expand Down Expand Up @@ -41,3 +59,10 @@ describe('map(arr, cb)', function() {
expect(squares).toEqual([1, 4, 9, 16, 25]);
});
});

describe('filter(array)', function() {
it('should return an array conteining the words that starts with "a"', function() {
var array = ['abajo', 'pera', 'escalera', 'alerta', 'indice', 'azteca', 'arbol', 'buzo'];
expect(filter(array)).toEqual(["abajo", "alerta", "azteca", "arbol"]);
});
});