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
17 changes: 17 additions & 0 deletions src/helperise/max_min_helpers/eyi_to_kere_ju.js
Original file line number Diff line number Diff line change
@@ -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;
17 changes: 17 additions & 0 deletions src/helperise/max_min_helpers/eyi_to_tobi_ju.js
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 2 additions & 0 deletions src/helperise/registeredHelperIse.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
28 changes: 28 additions & 0 deletions src/tests/helperise/max_min_helpers/eyi_to_kere_ju.js
Original file line number Diff line number Diff line change
@@ -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");
});
});
28 changes: 28 additions & 0 deletions src/tests/helperise/max_min_helpers/eyi_to_tobi_ju.js
Original file line number Diff line number Diff line change
@@ -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");
});
});