-
-
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.
- Loading branch information
Showing
12 changed files
with
4,205 additions
and
4,218 deletions.
There are no files selected for viewing
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
44 changes: 21 additions & 23 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,25 +1,23 @@ | ||
'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,16 +1,14 @@ | ||
'use strict'; | ||
var __importDefault = | ||
(this && this.__importDefault) || | ||
function (mod) { | ||
return mod && mod.__esModule ? mod : { default: mod }; | ||
}; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
const snappleFacts_1 = __importDefault(require('../../snappleFacts')); | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const snappleFacts_1 = __importDefault(require("../../snappleFacts")); | ||
/** | ||
* Retrieves an array of Snapple facts. | ||
* @returns {SnappleFact[]} An array of Snapple facts. | ||
*/ | ||
const GetFacts = () => { | ||
return snappleFacts_1.default; | ||
return snappleFacts_1.default; | ||
}; | ||
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,26 +1,24 @@ | ||
'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 with sources', () => { | ||
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(); | ||
}); | ||
it('should return an array of SnappleFacts with sources', () => { | ||
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,12 +1,12 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
* Retrieves an array of fact strings from an array of SnappleFact objects. | ||
* | ||
* @param snappleFacts - An array of SnappleFact objects. | ||
* @returns An array of fact strings. | ||
*/ | ||
const ListFacts = snappleFacts => { | ||
return snappleFacts.map(fact => fact.fact); | ||
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,26 +1,24 @@ | ||
'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,18 +1,16 @@ | ||
'use strict'; | ||
var __importDefault = | ||
(this && this.__importDefault) || | ||
function (mod) { | ||
return mod && mod.__esModule ? mod : { default: mod }; | ||
}; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
const crypto_1 = __importDefault(require('crypto')); | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const crypto_1 = __importDefault(require("crypto")); | ||
/** | ||
* Retrieves a random SnappleFact from the given array of SnappleFacts. | ||
* @param {SnappleFact[]} snappleFacts - The array of SnappleFacts to choose from. | ||
* @returns {SnappleFact} - A random SnappleFact. | ||
*/ | ||
const RandomFact = snappleFacts => { | ||
const randomIndex = crypto_1.default.randomInt(0, snappleFacts.length); | ||
return snappleFacts[randomIndex]; | ||
const RandomFact = (snappleFacts) => { | ||
const randomIndex = crypto_1.default.randomInt(0, 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,18 +1,16 @@ | ||
'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,55 +1,53 @@ | ||
'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_1 = __importDefault(require('./snappleFacts')); | ||
"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_1 = __importDefault(require("./snappleFacts")); | ||
/** | ||
* Represents a collection of Snapple facts. | ||
*/ | ||
class SnappleFacts { | ||
/** | ||
* Creates a new instance of the class. | ||
*/ | ||
constructor() { | ||
this.snappleFacts = snappleFacts_1.default; | ||
} | ||
/** | ||
* Retrieves an array of Snapple facts. | ||
* | ||
* @returns {SnappleFact[]} An array of Snapple facts. | ||
*/ | ||
getFacts() { | ||
return (0, getFacts_1.default)(); | ||
} | ||
/** | ||
* Retrieves a list of Snapple facts. | ||
* | ||
* @returns An array of strings representing the Snapple facts. | ||
*/ | ||
listFacts() { | ||
return (0, listFacts_1.default)(this.snappleFacts); | ||
} | ||
/** | ||
* Retrieves a SnappleFact by its number. | ||
* @param number - The number of the SnappleFact to retrieve. | ||
* @returns The SnappleFact object if found, otherwise undefined. | ||
*/ | ||
getFactByNumber(number) { | ||
return (0, getFactByNumber_1.default)({ snappleFacts: this.snappleFacts, number }); | ||
} | ||
/** | ||
* Retrieves a random SnappleFact from the collection of Snapple facts. | ||
* @returns {SnappleFact} A random SnappleFact. | ||
*/ | ||
randomFact() { | ||
return (0, randomFact_1.default)(this.snappleFacts); | ||
} | ||
/** | ||
* Creates a new instance of the class. | ||
*/ | ||
constructor() { | ||
this.snappleFacts = snappleFacts_1.default; | ||
} | ||
/** | ||
* Retrieves an array of Snapple facts. | ||
* | ||
* @returns {SnappleFact[]} An array of Snapple facts. | ||
*/ | ||
getFacts() { | ||
return (0, getFacts_1.default)(); | ||
} | ||
/** | ||
* Retrieves a list of Snapple facts. | ||
* | ||
* @returns An array of strings representing the Snapple facts. | ||
*/ | ||
listFacts() { | ||
return (0, listFacts_1.default)(this.snappleFacts); | ||
} | ||
/** | ||
* Retrieves a SnappleFact by its number. | ||
* @param number - The number of the SnappleFact to retrieve. | ||
* @returns The SnappleFact object if found, otherwise undefined. | ||
*/ | ||
getFactByNumber(number) { | ||
return (0, getFactByNumber_1.default)({ snappleFacts: this.snappleFacts, number }); | ||
} | ||
/** | ||
* Retrieves a random SnappleFact from the collection of Snapple facts. | ||
* @returns {SnappleFact} A random SnappleFact. | ||
*/ | ||
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 }); |
Oops, something went wrong.