-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update code formatting and version numbers
- Loading branch information
Showing
12 changed files
with
142 additions
and
131 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const GetFactByNumber = (args) => { | ||
const { snappleFacts, number } = args; | ||
if (number < 1 || number > snappleFacts.length) | ||
throw new Error('Invalid number'); | ||
return snappleFacts.find(fact => fact.number === number); | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
const GetFactByNumber = args => { | ||
const { snappleFacts, number } = args; | ||
if (number < 1 || number > snappleFacts.length) throw new Error('Invalid number'); | ||
return snappleFacts.find(fact => fact.number === number); | ||
}; | ||
exports.default = GetFactByNumber; |
44 changes: 23 additions & 21 deletions
44
src/functions/getFactByNumber/tests/getFactByNumber.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,25 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const getFactByNumber_1 = __importDefault(require("../getFactByNumber")); | ||
'use strict'; | ||
var __importDefault = | ||
(this && this.__importDefault) || | ||
function (mod) { | ||
return mod && mod.__esModule ? mod : { default: mod }; | ||
}; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
const getFactByNumber_1 = __importDefault(require('../getFactByNumber')); | ||
describe('getFactByNumber', () => { | ||
it('should return a fact for a valid number', () => { | ||
const snappleFacts = [ | ||
{ number: 1, fact: 'fact 1' }, | ||
{ number: 2, fact: 'fact 2' }, | ||
]; | ||
const fact = (0, getFactByNumber_1.default)({ snappleFacts, number: 1 }); | ||
expect(fact).toEqual({ number: 1, fact: 'fact 1' }); | ||
}); | ||
it('should throw an error for an invalid number', () => { | ||
const snappleFacts = [ | ||
{ number: 1, fact: 'fact 1' }, | ||
{ number: 2, fact: 'fact 2' }, | ||
]; | ||
expect(() => (0, getFactByNumber_1.default)({ snappleFacts, number: 3 })).toThrow('Invalid number'); | ||
}); | ||
it('should return a fact for a valid number', () => { | ||
const snappleFacts = [ | ||
{ number: 1, fact: 'fact 1' }, | ||
{ number: 2, fact: 'fact 2' }, | ||
]; | ||
const fact = (0, getFactByNumber_1.default)({ snappleFacts, number: 1 }); | ||
expect(fact).toEqual({ number: 1, fact: 'fact 1' }); | ||
}); | ||
it('should throw an error for an invalid number', () => { | ||
const snappleFacts = [ | ||
{ number: 1, fact: 'fact 1' }, | ||
{ number: 2, fact: 'fact 2' }, | ||
]; | ||
expect(() => (0, getFactByNumber_1.default)({ snappleFacts, number: 3 })).toThrow('Invalid number'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const snappleFacts_json_1 = __importDefault(require("../../snappleFacts.json")); | ||
'use strict'; | ||
var __importDefault = | ||
(this && this.__importDefault) || | ||
function (mod) { | ||
return mod && mod.__esModule ? mod : { default: mod }; | ||
}; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
const snappleFacts_json_1 = __importDefault(require('../../snappleFacts.json')); | ||
const GetFacts = () => { | ||
return snappleFacts_json_1.default.snapplefacts; | ||
return snappleFacts_json_1.default.snapplefacts; | ||
}; | ||
exports.default = GetFacts; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,22 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const getFacts_1 = __importDefault(require("../getFacts")); | ||
'use strict'; | ||
var __importDefault = | ||
(this && this.__importDefault) || | ||
function (mod) { | ||
return mod && mod.__esModule ? mod : { default: mod }; | ||
}; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
const getFacts_1 = __importDefault(require('../getFacts')); | ||
describe('GetFacts', () => { | ||
it('should return an array of SnappleFacts', () => { | ||
const facts = (0, getFacts_1.default)(); | ||
expect(facts.length).toBeGreaterThan(0); | ||
}); | ||
it('should return an array of SnappleFacts with numbers', () => { | ||
const facts = (0, getFacts_1.default)(); | ||
expect(facts[0].number).toBeDefined(); | ||
}); | ||
it('should return an array of SnappleFacts with facts', () => { | ||
const facts = (0, getFacts_1.default)(); | ||
expect(facts[0].fact).toBeDefined(); | ||
}); | ||
it('should return an array of SnappleFacts', () => { | ||
const facts = (0, getFacts_1.default)(); | ||
expect(facts.length).toBeGreaterThan(0); | ||
}); | ||
it('should return an array of SnappleFacts with numbers', () => { | ||
const facts = (0, getFacts_1.default)(); | ||
expect(facts[0].number).toBeDefined(); | ||
}); | ||
it('should return an array of SnappleFacts with facts', () => { | ||
const facts = (0, getFacts_1.default)(); | ||
expect(facts[0].fact).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const ListFacts = (snappleFacts) => { | ||
return snappleFacts.map(fact => fact.fact); | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
const ListFacts = snappleFacts => { | ||
return snappleFacts.map(fact => fact.fact); | ||
}; | ||
exports.default = ListFacts; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,26 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const listFacts_1 = __importDefault(require("../listFacts")); | ||
'use strict'; | ||
var __importDefault = | ||
(this && this.__importDefault) || | ||
function (mod) { | ||
return mod && mod.__esModule ? mod : { default: mod }; | ||
}; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
const listFacts_1 = __importDefault(require('../listFacts')); | ||
describe('ListFacts', () => { | ||
it('should return an array of strings', () => { | ||
const snappleFacts = [ | ||
{ fact: 'Fact 1', number: 1 }, | ||
{ fact: 'Fact 2', number: 2 }, | ||
{ fact: 'Fact 3', number: 3 }, | ||
]; | ||
const expected = ['Fact 1', 'Fact 2', 'Fact 3']; | ||
const actual = (0, listFacts_1.default)(snappleFacts); | ||
expect(actual).toEqual(expected); | ||
}); | ||
it('should return an empty array when given an empty array', () => { | ||
const snappleFacts = []; | ||
const expected = []; | ||
const actual = (0, listFacts_1.default)(snappleFacts); | ||
expect(actual).toEqual(expected); | ||
}); | ||
it('should return an array of strings', () => { | ||
const snappleFacts = [ | ||
{ fact: 'Fact 1', number: 1 }, | ||
{ fact: 'Fact 2', number: 2 }, | ||
{ fact: 'Fact 3', number: 3 }, | ||
]; | ||
const expected = ['Fact 1', 'Fact 2', 'Fact 3']; | ||
const actual = (0, listFacts_1.default)(snappleFacts); | ||
expect(actual).toEqual(expected); | ||
}); | ||
it('should return an empty array when given an empty array', () => { | ||
const snappleFacts = []; | ||
const expected = []; | ||
const actual = (0, listFacts_1.default)(snappleFacts); | ||
expect(actual).toEqual(expected); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const RandomFact = (snappleFacts) => { | ||
const randomIndex = Math.floor(Math.random() * snappleFacts.length); | ||
return snappleFacts[randomIndex]; | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
const RandomFact = snappleFacts => { | ||
const randomIndex = Math.floor(Math.random() * snappleFacts.length); | ||
return snappleFacts[randomIndex]; | ||
}; | ||
exports.default = RandomFact; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,18 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const randomFact_1 = __importDefault(require("../randomFact")); | ||
'use strict'; | ||
var __importDefault = | ||
(this && this.__importDefault) || | ||
function (mod) { | ||
return mod && mod.__esModule ? mod : { default: mod }; | ||
}; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
const randomFact_1 = __importDefault(require('../randomFact')); | ||
describe('RandomFact', () => { | ||
it('should return a random fact', () => { | ||
const snappleFacts = [ | ||
{ number: 1, fact: 'fact 1' }, | ||
{ number: 2, fact: 'fact 2' }, | ||
]; | ||
const fact = (0, randomFact_1.default)(snappleFacts); | ||
expect(fact).toBeDefined(); | ||
}); | ||
it('should return a random fact', () => { | ||
const snappleFacts = [ | ||
{ number: 1, fact: 'fact 1' }, | ||
{ number: 2, fact: 'fact 2' }, | ||
]; | ||
const fact = (0, randomFact_1.default)(snappleFacts); | ||
expect(fact).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,30 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const getFactByNumber_1 = __importDefault(require("./functions/getFactByNumber/getFactByNumber")); | ||
const getFacts_1 = __importDefault(require("./functions/getFacts/getFacts")); | ||
const listFacts_1 = __importDefault(require("./functions/listFacts/listFacts")); | ||
const randomFact_1 = __importDefault(require("./functions/randomFact/randomFact")); | ||
const snappleFacts_json_1 = __importDefault(require("./snappleFacts.json")); | ||
'use strict'; | ||
var __importDefault = | ||
(this && this.__importDefault) || | ||
function (mod) { | ||
return mod && mod.__esModule ? mod : { default: mod }; | ||
}; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
const getFactByNumber_1 = __importDefault(require('./functions/getFactByNumber/getFactByNumber')); | ||
const getFacts_1 = __importDefault(require('./functions/getFacts/getFacts')); | ||
const listFacts_1 = __importDefault(require('./functions/listFacts/listFacts')); | ||
const randomFact_1 = __importDefault(require('./functions/randomFact/randomFact')); | ||
const snappleFacts_json_1 = __importDefault(require('./snappleFacts.json')); | ||
class SnappleFacts { | ||
constructor() { | ||
this.snappleFacts = snappleFacts_json_1.default.snapplefacts; | ||
} | ||
getFacts() { | ||
return (0, getFacts_1.default)(); | ||
} | ||
listFacts() { | ||
return (0, listFacts_1.default)(this.snappleFacts); | ||
} | ||
getFactByNumber(number) { | ||
return (0, getFactByNumber_1.default)({ snappleFacts: this.snappleFacts, number }); | ||
} | ||
randomFact() { | ||
return (0, randomFact_1.default)(this.snappleFacts); | ||
} | ||
constructor() { | ||
this.snappleFacts = snappleFacts_json_1.default.snapplefacts; | ||
} | ||
getFacts() { | ||
return (0, getFacts_1.default)(); | ||
} | ||
listFacts() { | ||
return (0, listFacts_1.default)(this.snappleFacts); | ||
} | ||
getFactByNumber(number) { | ||
return (0, getFactByNumber_1.default)({ snappleFacts: this.snappleFacts, number }); | ||
} | ||
randomFact() { | ||
return (0, randomFact_1.default)(this.snappleFacts); | ||
} | ||
} | ||
exports.default = SnappleFacts; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
"use strict"; | ||
'use strict'; | ||
describe('Test', () => { | ||
it('should pass', () => { | ||
expect(true).toBe(true); | ||
}); | ||
it('should pass', () => { | ||
expect(true).toBe(true); | ||
}); | ||
}); |