diff --git a/src/helperise/max_min_helpers/eyi_to_kere_ju.js b/src/helperise/max_min_helpers/eyi_to_kere_ju.js new file mode 100644 index 0000000..a9b2f21 --- /dev/null +++ b/src/helperise/max_min_helpers/eyi_to_kere_ju.js @@ -0,0 +1,17 @@ +/** + * Get the minimum oflist of numbers + * input can either be an array or a number of arguments seperated by a ',' + * note that if the first argument is an array, all other arguments are neglected + * @returns {[number]} minimumNumber + */ +function eyiToKereJu (args) { + if (Array.isArray(args)) { + if (Array.isArray(args[0])) args = args[0]; + const min = Math.min(...args); + if (Number.isNaN(min)) throw new Error("Invalid number params passed to eyiToKereJu"); + return min; + } + throw new Error("Yorlang System Error: args should be an array"); +} + +module.exports = eyiToKereJu; diff --git a/src/helperise/max_min_helpers/eyi_to_tobi_ju.js b/src/helperise/max_min_helpers/eyi_to_tobi_ju.js new file mode 100644 index 0000000..abc2cd7 --- /dev/null +++ b/src/helperise/max_min_helpers/eyi_to_tobi_ju.js @@ -0,0 +1,17 @@ +/** + * Get the maximum of list of numbers, + * input can either be an array or a number of arguments seperated by a ',' + * note that if the first argument is an array, all other arguments are neglected + * @returns {[number]} maximumNumber + */ +function eyiToTobiJu (args) { + if (Array.isArray(args)) { + if (Array.isArray(args[0])) args = args[0]; + const max = Math.max(...args); + if (Number.isNaN(max)) throw new Error("Invalid number params passed to eyiToTobiJu"); + return max; + } + throw new Error("Yorlang System Error: args should be an array"); +} + +module.exports = eyiToTobiJu; diff --git a/src/helperise/registeredHelperIse.js b/src/helperise/registeredHelperIse.js index 4893b58..cc23c10 100644 --- a/src/helperise/registeredHelperIse.js +++ b/src/helperise/registeredHelperIse.js @@ -4,5 +4,7 @@ helperIseDeclarations["siLetaNla"] = require("./string_helpers/si_leta_nla.js"); helperIseDeclarations["siLetaKekere"] = require("./string_helpers/si_leta_kekere.js"); helperIseDeclarations["teSibi"] = require("./input_output/tesibi.js"); helperIseDeclarations["aago"] = require("./datetime_helpers/aago.js"); +helperIseDeclarations["eyiToKereJu"] = require("./max_min_helpers/eyi_to_kere_ju.js"); +helperIseDeclarations["eyiToTobiJu"] = require("./max_min_helpers/eyi_to_tobi_ju.js"); module.exports = helperIseDeclarations; diff --git a/src/tests/helperise/max_min_helpers/eyi_to_kere_ju.js b/src/tests/helperise/max_min_helpers/eyi_to_kere_ju.js new file mode 100644 index 0000000..d138707 --- /dev/null +++ b/src/tests/helperise/max_min_helpers/eyi_to_kere_ju.js @@ -0,0 +1,28 @@ +const oKereJulo = require("../../../helperise/max_min_helpers/eyi_to_kere_ju.js"); + +describe("eyiToKereJu Test suite", () => { + test("It should return minimum numnber in the array", () => { + const array = [34,44,455,54, ]; + expect(eyiToKereJu(array)).toBe(34); + }); + + test("It should return minimum numnber in the array", () => { + const array = ['34','44','455','54', ]; + expect(() => eyiToKereJu(array)).toBe(34); + }); + + test("It should fail because helper function OkereJulo accepts only an array of numbers as argument", () => { + const array = ['34','44','455','54','fsfghfsf' ]; + expect(() => eyiToKereJu(array)).toThrow("element of array must be a number"); + }); + + test("It should ignore other arguments and return minimum number in the array which is the first argument", () => { + const array = [[34,44,455],54,'fsfghfsf' ]; + expect(() => eyiToKereJu(array)).toBe(34); + }); + + test("It should fail because helper function eyiToKereJu expects an array as argument", () => { + const array = 8; + expect(() => eyiToKereJu(array)).toThrow("Yorlang system error"); + }); +}); diff --git a/src/tests/helperise/max_min_helpers/eyi_to_tobi_ju.js b/src/tests/helperise/max_min_helpers/eyi_to_tobi_ju.js new file mode 100644 index 0000000..b291dd5 --- /dev/null +++ b/src/tests/helperise/max_min_helpers/eyi_to_tobi_ju.js @@ -0,0 +1,28 @@ +const oTobiJulo = require("../../../helperise/max_min_helpers/eyi_to_tobi_ju.js"); + +describe("eyiToTobiJu Test suite", () => { + test("It should return maximum numnber in the array", () => { + const array = [34,44,455,54, ]; + expect(eyiToTobiJu(array)).toBe(455); + }); + + test("It should return maximum numnber in the array", () => { + const array = ['34','44','455','54', ]; + expect(() => eyiToTobiJu(array)).toBe(455); + }); + + test("It should fail because helper function oTobiJulo accepts only an array of numbers as argument", () => { + const array = ['34','44','455','54','fsfghfsf', ]; + expect(() => eyiToTobiJu(array)).toThrow("element of array must be a number"); + }); + + test("It should ignore other arguments and return maximum number in the array which is the first argument", () => { + const array = [[34,44,455],54,'fsfghfsf' ]; + expect(() => eyiToTobiJu(array)).toBe(455); + }); + + test("It should fail because helper function eyiToTobiJu expects an array as argument", () => { + const array = 8; + expect(() => eyiToTobiJu(array)).toThrow("Yorlang system error"); + }); +});