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
43 changes: 31 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 16 additions & 1 deletion src/kata1.fizzBuzz.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
const fizzBuzz = number => {};
const fizzBuzz = number => {

@ersel ersel Nov 14, 2020

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I try to avoid chaining ternaries as they get harder to read...

you could have considered if, or switch here.

return number % 3 === 0 && number % 5 === 0 ? "FizzBuzz"
: number % 3 === 0 ? "Fizz"
: number % 5 === 0 ? "Buzz"
: number;
};



module.exports = fizzBuzz;


// how to decide whic solution is best:
// Who is going to use or read the code?
// Do we want to prioritize readability?
// For example by putting the checking into separate clearly named functions
// that make it easy for any reader to know what's going on?
// or de want to avoid being verbose?
4 changes: 3 additions & 1 deletion src/kata2.booleanToWord.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const booleanToWord = boolean => {};
const booleanToWord = boolean => {
return boolean ? "Yes" : "No";
};

module.exports = booleanToWord;
14 changes: 13 additions & 1 deletion src/kata3.numberToReversedDigits.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
const numberToReversedDigits = number => {};
const numberToReversedDigits = number => {
const stringified = String(number);
const arrayed = stringified.split("");
const numberfied = arrayed.map(char => Number(char));
return numberfied.reverse();
};


// less verbose, more chained

const numberToReversedDigitsChain = number => {
return String(number).split("").map(char => Number(char)).reverse();

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I would have done it like this, using chained...

};

module.exports = numberToReversedDigits;
21 changes: 20 additions & 1 deletion src/kata4.humanCatDogYears.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
const humanCatDogYears = number => {};
const calculateAnimalYears = (animal, number) => {
let factor = animal === "dog" ? 5 : animal === "cat" ? 4 : console.error("animal not recognised");

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

again, don't chain ternaries like this


if (number === 1) {
animalYears = 15;
} else if (number === 2) {
animalYears = 24;
} else {
animalYears = ((number - 2) * factor) + 24;
}
return animalYears;
}


const humanCatDogYears = number => {
let catYears = calculateAnimalYears("cat", number)
let dogYears = calculateAnimalYears("dog", number)
return [number, catYears, dogYears]
};

module.exports = humanCatDogYears;

11 changes: 10 additions & 1 deletion src/kata5.reachDestination.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
const reachDestination = (distance, speed) => {};
const reachDestination = (distance, speed) => {
const time = (Math.ceil((distance / speed) * 2) / 2);
return `I should be there in ${time} hours.`
};

module.exports = reachDestination;






16 changes: 15 additions & 1 deletion src/kata6.joinNames.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
const joinNames = namesObj => {};
const joinNames = namesObjArray => {
const names = namesObjArray.map((person, index) => {

if (index === namesObjArray.length - 1){

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

nice solution

return `& ${person.name}`
} else if (index === namesObjArray.length - 2){
return `${person.name}`
} else {
return `${person.name},`
}
})

return names.join(' ');
};

module.exports = joinNames;

17 changes: 16 additions & 1 deletion src/kata7.getEmployerRole.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
const getEmployerRole = (employeeName, employees) => {};
const getEmployerRole = (employeeName, employees) => {
return employees.find(emp => emp.name === employeeName).role;
};


module.exports = getEmployerRole;





//Function with 2 parameters including a employeeName(string) and an employees(array)

///Write a function that takes in an array of objects and a string- which is a name

////And we need to return from the function the employee role

// e.g getEmployerRole('Satti', employees) should return 'Developer'
24 changes: 20 additions & 4 deletions test/kata1.fizzBuzz.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
const { fizzBuzz } = require("../src");

describe("fizzBuzz", () => {
test("returns Fizz when passed a multiple of 3", () => {});
it("returns Fizz when passed a multiple of 3", () => {
expect(fizzBuzz(9)).toEqual("Fizz");
expect(fizzBuzz(33)).toEqual("Fizz");
expect(fizzBuzz(57)).toEqual("Fizz");
});

test("returns Buzz when passed a multiple of 5", () => {});
it("returns Buzz when passed a multiple of 5", () => {
expect(fizzBuzz(10)).toEqual("Buzz");
expect(fizzBuzz(35)).toEqual("Buzz");
expect(fizzBuzz(100)).toEqual("Buzz");
});

test("returns FizzBuzz when passed a multiple 3 and 5", () => {});
it("returns FizzBuzz when passed a multiple 3 and 5", () => {
expect(fizzBuzz(15)).toEqual("FizzBuzz");
expect(fizzBuzz(45)).toEqual("FizzBuzz");
expect(fizzBuzz(60)).toEqual("FizzBuzz");
});

test("returns the number when it isn't a multiple of 3 or 5", () => {});
it("returns the number when it isn't a multiple of 3 or 5", () => {
expect(fizzBuzz(4)).toEqual(4);
expect(fizzBuzz(11)).toEqual(11);
expect(fizzBuzz(131)).toEqual(131);
});
});
9 changes: 8 additions & 1 deletion test/kata2.booleanToWord.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
const { booleanToWord } = require("../src");

describe("booleanToWord", () => {
// how do we create specs again???

it((`should return "Yes" when passed true`), () => {
expect(booleanToWord(true)).toEqual("Yes");
});

it((`should return "No" when passed false`), () => {
expect(booleanToWord(false)).toEqual("No");
});
});
6 changes: 5 additions & 1 deletion test/kata3.numberToReversedDigits.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
const { numberToReversedDigits } = require("../src");

describe("numberToReversedDigits", () => {
test("returns a reversed array of the number's digits", () => {});
const number = 12345;

it("returns a reversed array of the number's digits", () => {
expect(numberToReversedDigits(number)).toEqual([5, 4, 3, 2, 1]);
});
});
26 changes: 25 additions & 1 deletion test/kata4.humanCatDogYears.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
const { humanCatDogYears } = require("../src");

// Look Ma, no handlebars!!!
describe("humanCatDogYears", () => {
it("should return an array with length 3", () => {
expect(humanCatDogYears(10)).toHaveLength(3)
});

it("should have the passed argument at index 0", () => {
expect(humanCatDogYears(10)[0]).toBe(10)
});

it("should have the equivalent cat years at index 1", () => {
expect(humanCatDogYears(10)[1]).toBe(56)
});

it("should have the equivalent dog years at index 2", () => {
expect(humanCatDogYears(10)[2]).toBe(64)
});

it("should return an array of 3 numbers: human, cat and dog years respectively", () => {
expect(humanCatDogYears(3)).toEqual([3, 28, 29])
expect(humanCatDogYears(6)).toEqual([6, 40, 44])
})

});


16 changes: 15 additions & 1 deletion test/kata5.reachDestination.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
const { reachDestination } = require("../src");

describe("reachDestination", () => {
test("returns string with estimated time of arrival", () => {});
test("returns a string", () => {
const result = reachDestination(44,10)
expect(typeof result).toBe("string");
});

test("returns string with estimated time of arrival", () => {
expect(reachDestination(44, 10)).toBe('I should be there in 4.5 hours.')
expect(reachDestination(48, 10)).toBe('I should be there in 5 hours.')
expect(reachDestination(500, 10)).toBe('I should be there in 50 hours.')
});

});




Loading