Skip to content
This repository has been archived by the owner on Feb 24, 2020. It is now read-only.

[WIP] Segment-1 #21

Open
wants to merge 3 commits into
base: segment-1
Choose a base branch
from
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 __test__/daysInMonth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ const { countDaysInMonth } = require('../src/daysInMonth');
describe('countDaysInMonth', () => {
test('should return correct number of days', () => {
expect(countDaysInMonth(2014, 4)).toBe(30);
expect(countDaysInMonth(2016, 1)).toBe(29);
expect(countDaysInMonth(2016, 2)).toBe(29);
});
});
3 changes: 2 additions & 1 deletion src/boolean.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

// Return a boolean

const a = 5;
const a = Boolean(5);

module.exports = a;

21 changes: 20 additions & 1 deletion src/daysInMonth.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,26 @@
// countDaysInMonth(2016, 8); //=> 30

function countDaysInMonth(year, month) {
return year + month;
let leap = false;

let days;
if (year % 4 === 0) {
leap = true;
}

if (month === 1 || month === 3 || month === 5 || month === 7 || month === 8 ||
month === 10 || month === 12) {
days = 31;
} else if (month === 2) {
if (leap) {
days = 29;
} else {
days = 28;
}
} else {
days = 30;
}
return days;
}

module.exports = { countDaysInMonth };
10 changes: 8 additions & 2 deletions src/invertKeyValue.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
// invertKv({foo: 'bar', unicorn: 'rainbow'});
// => {bar: 'foo', rainbow: 'unicorn'}

function invertKeyValue() {

function invertKeyValue(obj) {
let obj2 = {};
obj2 = Object.keys(obj).reduce((acc, key) => {
acc[obj[key]] = key;
return acc;
}, {});
return obj2;
}

module.exports = invertKeyValue;

11 changes: 9 additions & 2 deletions src/lowercaseKeys.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
// lowercaseKeys({FOO: true, bAr: false});
// => { foo: true, bar: false }

function lowercaseKeys() {

function lowercaseKeys(obj) {
let obj2 = {};
let key2;
obj2 = Object.keys(obj).reduce((acc, key) => {
key2 = key.toLocaleLowerCase();
acc[key2] = obj[key];
return acc;
}, {});
return obj2;
}

module.exports = lowercaseKeys;