Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nom_modules
node_modules
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
15 changes: 15 additions & 0 deletions 00-imperative/js/feedMonkeys.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,18 @@
*/

const MONKEYS = ["🐒", "🦍", "🦧"];

const feedMonkeys = function (fruit) {
const monkeys = [];

const collectionlength = MONKEYS.length;

for (let index = 0; index < collectionlength; index++) {
const monkey = `${MONKEYS[index]} ${fruit}`;
monkeys.push(monkey);
}

return monkeys;
};

export default feedMonkeys;
21 changes: 21 additions & 0 deletions 00-imperative/js/feedMonkeys.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import feedMonkeys from "./feedMonkeys.js";
describe("Given feedMonkeys", () => {
test("when 🍌 is provided as argument Then exècted array should be returned ", () => {
const fruit = "🍌";
const EXPECTED_RESULT = ["🐒 🍌", "🦍 🍌", "🦧 🍌"];

const Monkeys = feedMonkeys(fruit);

expect(Monkeys).toBeDefined();
expect(Monkeys).toEqual(EXPECTED_RESULT);
});
test("when 🍎 is provided as argument Then exècted array should be returned ", () => {
const fruit = "🍎";
const EXPECTED_RESULT = ["🐒 🍎", "🦍 🍎", "🦧 🍎"];

const Monkeys = feedMonkeys(fruit);

expect(Monkeys).toBeDefined();
expect(Monkeys).toEqual(EXPECTED_RESULT);
});
});
16 changes: 16 additions & 0 deletions 00-imperative/js/getLongWords.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,19 @@

const LANGUAGES = ["Java", "C++", "JavaScript", "C#", "TypeScript"];
const BEATLES = ["John", "George", "Paul", "Ringo"];

const getLongWords = function (WORDS) {
const expectedWords = [];
const collectionLength = WORDS.length;

for (let index = 0; index < collectionLength; index++) {
if (WORDS[index].length >= 5) {
const Word = WORDS[index];
expectedWords.push(Word);
}
}

return expectedWords;
};

export default getLongWords;
21 changes: 21 additions & 0 deletions 00-imperative/js/getLongWords.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import getLongWords from "./getLongWords.js";
describe("Given getLongWords", () => {
test("when [Java, C++, JavaScript, C#, TypeScript] is provided as argument Then exècted array should be returned ", () => {
const WORDS = ["Java", "C++", "JavaScript", "C#", "TypeScript"];
const EXPECTED_RESULT = ["JavaScript", "TypeScript"];

const newCollection = getLongWords(WORDS);

expect(newCollection).toBeDefined();
expect(newCollection).toEqual(EXPECTED_RESULT);
});
test("when [John, George, Paul, Ringo] is provided as argument Then exècted array should be returned ", () => {
const WORDS = ["John", "George", "Paul", "Ringo"];
const EXPECTED_RESULT = ["George", "Ringo"];

const newCollection = getLongWords(WORDS);

expect(newCollection).toBeDefined();
expect(newCollection).toEqual(EXPECTED_RESULT);
});
});
11 changes: 11 additions & 0 deletions 00-imperative/js/sumNumbersFromInitialValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,14 @@
*/

const NUMBERS = [1, 2, 3, 4, 5];

const sumNumbersFromInitialValue = function (numbers, inicial) {
let suma = inicial;
const collectionLength = numbers.length;
for (let index = 0; index < collectionLength; index++) {
suma += numbers[index];
}
return suma;
};

export default sumNumbersFromInitialValue;
23 changes: 23 additions & 0 deletions 00-imperative/js/sumNumbersFromInitialValue.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import sumNumbersFromInitialValue from "./sumNumbersFromInitialValue.js";
describe("Given sumNumbersFromInitialValue", () => {
test("when an array of numbers and an initialValue is given as an argument, the sum of the values in the array starting at the initialValue is returned ", () => {
const NUMBERS = [1, 2, 3, 4, 5];
const initialValue = 0;
const EXPECTED_RESULT = 15;

const sum = sumNumbersFromInitialValue(NUMBERS, initialValue);

expect(sum).toBeDefined();
expect(sum).toEqual(EXPECTED_RESULT);
});
test("when an array of numbers and an initialValue is given as an argument, the sum of the values in the array starting at the initialValue is returned ", () => {
const NUMBERS = [1, 2, 3, 4, 5];
const initialValue = 10;
const EXPECTED_RESULT = 25;

const sum = sumNumbersFromInitialValue(NUMBERS, initialValue);

expect(sum).toBeDefined();
expect(sum).toEqual(EXPECTED_RESULT);
});
});
8 changes: 8 additions & 0 deletions 01-map/capitalizeMates.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,11 @@
*/

const MATES = ["john", "JACOB", "jinGleHeimer", "schmidt"];

function capitalizeMates(mates) {
return mates.map(
(name) => name.charAt(0).toUpperCase() + name.slice(1).toLowerCase(),
);
}

export default capitalizeMates;
12 changes: 12 additions & 0 deletions 01-map/capitalizeMates.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import capitalizeMates from "./capitalizeMates.js";

describe("capitalizeMates function", () => {
test("capitalizes names in the array", () => {
const inputMates = ["john", "JACOB", "jinGleHeimer", "schmidt"];
const expectedOutput = ["John", "Jacob", "Jingleheimer", "Schmidt"];

const result = capitalizeMates(inputMates);

expect(result).toEqual(expectedOutput);
});
});
13 changes: 13 additions & 0 deletions 01-map/extendUsersSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,16 @@ const USERS = [
isEnabled: true
},];
*/

function extendUsersSettings(users) {
return users.map((user, index) => ({
...user,
id: index,
isEnabled: true,
}));
}

const extendedUsers = extendUsersSettings(USERS);
console.log(extendedUsers);

export default extendUsersSettings;
57 changes: 57 additions & 0 deletions 01-map/extendUsersSettings.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import extendUsersSettings from "./extendUsersSettings";

describe("extendUsersSettings function", () => {
test("extends users properties with id and isEnabled", () => {
const inputUsers = [
{
email: "lindsay.ferguson@reqres.in",
firstName: "Lindsay",
lastName: "Lawson",
avatar: "https://reqres.in/img/faces/7-image.jpg",
},
{
email: "michael.lawson@reqres.in",
firstName: "Michael",
lastName: "Ferguson",
avatar: "https://reqres.in/img/faces/8-image.jpg",
},
{
email: "tobias.funke@reqres.in",
firstName: "Tobias",
lastName: "Funke",
avatar: "https://reqres.in/img/faces/9-image.jpg",
},
];

const expectedOutput = [
{
email: "lindsay.ferguson@reqres.in",
firstName: "Lindsay",
lastName: "Lawson",
avatar: "https://reqres.in/img/faces/7-image.jpg",
id: 0,
isEnabled: true,
},
{
email: "michael.lawson@reqres.in",
firstName: "Michael",
lastName: "Ferguson",
avatar: "https://reqres.in/img/faces/8-image.jpg",
id: 1,
isEnabled: true,
},
{
email: "tobias.funke@reqres.in",
firstName: "Tobias",
lastName: "Funke",
avatar: "https://reqres.in/img/faces/9-image.jpg",
id: 2,
isEnabled: true,
},
];

const result = extendUsersSettings(inputUsers);

expect(result).toEqual(expectedOutput);
});
});
10 changes: 10 additions & 0 deletions 01-map/extractVipsNames.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,13 @@ const VIPS = [
age: 100,
},
];

function extractVipsNames(VIPS) {
const extractedNames = VIPS.map((vip) => {
return vip.name;
});

return extractedNames;
}

export default extractVipsNames;
19 changes: 19 additions & 0 deletions 01-map/extractVipsNames.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import extractVipsNames from "./extractVipsNames";

describe("extractVipsNames function", () => {
test("returns an array of strings with vips names", () => {
const inputVIPS = [
{ name: "Foo", age: 80 },
{ name: "Bar", age: 2 },
{ name: "Fizz", age: 5 },
{ name: "Buzz", age: 16 },
{ name: "FizzBuzz", age: 100 },
];

const expectedOutput = ["Foo", "Bar", "Fizz", "Buzz", "FizzBuzz"];

const result = extractVipsNames(inputVIPS);

expect(result).toEqual(expectedOutput);
});
});
13 changes: 13 additions & 0 deletions 01-map/feedMonkeys.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,17 @@
* expected: with 🍎 => ['🐒 🍎', '🦍 🍎', '🦧 🍎']
*/

import { features } from "caniuse-lite";
import feedMonkeys from "../00-imperative/js/feedMonkeys";

const MONKEYS = ["🐒", "🦍", "🦧"];

function extractVipsNames(fruit) {
const extractedNames = MONKEYS.map((monkey) => {
return `${monkey} ${fruit}`;
});

return extractedNames;
}

export default feedMonkeys;
21 changes: 21 additions & 0 deletions 01-map/feedMonkeys.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import feedMonkeys from "./feedMonkeys";

describe("feedMonkeys function", () => {
test("returns an array with each monkey having one fruit (🍌)", () => {
const fruit = "🍌";
const expectedOutput = ["🐒 🍌", "🦍 🍌", "🦧 🍌"];

const result = feedMonkeys(fruit);

expect(result).toEqual(expectedOutput);
});

test("returns an array with each monkey having one fruit (🍎)", () => {
const fruit = "🍎";
const expectedOutput = ["🐒 🍎", "🦍 🍎", "🦧 🍎"];

const result = feedMonkeys(fruit);

expect(result).toEqual(expectedOutput);
});
});
9 changes: 9 additions & 0 deletions 01-map/transformSecondsToWords.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,12 @@
*/

const SECONDS = [2, 5, 100];

function transformSecondsToWords(secondsArray) {
return secondsArray.map((seconds) => String(seconds));
}

const transformedWords = transformSecondsToWords(SECONDS);
console.log(transformedWords);

export default transformSecondsToWords;
12 changes: 12 additions & 0 deletions 01-map/transformSecondsToWords.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import transformSecondsToWords from "./transformSecondsToWords";

describe("transformSecondsToWords function", () => {
test("transforms numbers to strings", () => {
const inputSeconds = [2, 5, 100];
const expectedOutput = ["2", "5", "100"];

const result = transformSecondsToWords(inputSeconds);

expect(result).toEqual(expectedOutput);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,13 @@ const CUSTOMERS = [
member: true,
},
];

const customersWhoBelongToMembership = function (menbers) {
const clubMenbers = menbers.filter((menber) => {
return menber.member === true;
});

return clubMenbers;
};

export default customersWhoBelongToMembership;
38 changes: 38 additions & 0 deletions 02-filter/customersWhoBelongToMembership.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import customersWhoBelongToMembership from "./customersWhoBelongToMembership.js";
describe("Given customersWhoBelongToMembership", () => {
test("when an array of strings is given as an argument, then the exected array should be returned ", () => {
const CUSTOMERS = [
{
name: "Foo",
member: true,
},
{
name: "Bar",
member: false,
},
{
name: "Fizz",
member: true,
},
{
name: "Buzz",
member: false,
},
{
name: "FizzBuzz",
member: true,
},
];
const EXPECTED_RESULT = [
{ name: "Foo", member: true },
{ name: "Fizz", member: true },
{ name: "FizzBuzz", member: true },
];

const menbers = customersWhoBelongToMembership(CUSTOMERS);

expect(menbers).toBeDefined();
expect(menbers.length).toEqual(3);
expect(menbers).toEqual(EXPECTED_RESULT);
});
});
10 changes: 10 additions & 0 deletions 02-filter/extractCountriesWithFiveCharactersOrFewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,13 @@
*/

const COUNTRIES = ["United Kingdom", "Italy", "France", "Portugal", "Greece"];

const extractCountriesWithFiveCharactersOrFewer = function (countries) {
const countriesFilter = countries.filter((countrie) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const countriesFilter = countries.filter((countrie) => {
const countriesFilter = countries.filter((country) => {

return countrie.length <= 5;
});

return countriesFilter;
};

export default extractCountriesWithFiveCharactersOrFewer;
Loading