Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new helpers for square root, word count, random string #62

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 18 additions & 0 deletions src/helperise/math_helpers/nombalasan.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/** Takes any number
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add test cases for each of these methods

* Returns absolute value of number
*
* @returns {number}
*/
function nombalasan (args) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use camel casing. nonbaLasan

if (Array.isArray(args)) {
let [ number, ] = args;

if (!isNaN(number)) {
return Math.abs(number);
}
throw new Error("Param must be a number");
}
throw new Error("Yorlang system error");
}

module.exports = nombalasan;
18 changes: 18 additions & 0 deletions src/helperise/math_helpers/onigun_merin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/** Takes a number
* Returns square root of number
*
* @returns {number}
*/
function igunmerin (args) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use camel casing. square root is Irìn kejì in yoruba

if (Array.isArray(args)) {
let [ number, ] = args;

if (!isNaN(number)) {
return Math.sqrt(number);
}
throw new Error("Param must be a number");
}
throw new Error("Yorlang system error");
}

module.exports = igunmerin;
23 changes: 23 additions & 0 deletions src/helperise/random_helpers/yipo_oro.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Returns a random number between two values (0 -> 1 by default)
* - If only one argument is specified, that will become the maximum range, with 0 as the minimum.
* - If two arguments are specified, the first will be the minimum, and the second will be the maximum.
*
* @returns {number}
*/
function yipooro (args) {
if (Array.isArray(args)) {
let [ length, ] = args;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const is preferred in yorlang codebase whenever a variable is not re-assigned


var result = "";
var characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
var charactersLength = characters.length;
for (var i = 0; i < length; i++) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use let for block variables

result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}
throw new Error("Yorlang system error");
}

module.exports = yipooro;
6 changes: 6 additions & 0 deletions src/helperise/registeredHelperIse.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,11 @@ helperIseDeclarations["fiRopo"] = require("./string_helpers/fi_ro_po.js");
helperIseDeclarations["teSibi"] = require("./input_output/tesibi.js");
helperIseDeclarations["aago"] = require("./datetime_helpers/aago.js");
helperIseDeclarations["yipo"] = require("./random_helpers/yipo.js");
helperIseDeclarations["pipoto"] = require("./string_helpers/pipoto.js");
helperIseDeclarations["pinoro"] = require("./string_helpers/okun_pin_si_orun.js");
helperIseDeclarations["yipooro"] = require("./random_helpers/yipo_oro.js");
helperIseDeclarations["iyeoro"] = require("./string_helpers/iye_oro.js");
helperIseDeclarations["nombalasan"] = require("./math_helpers/nombalasan.js");
helperIseDeclarations["igunmerin"] = require("./math_helpers/onigun_merin.js");

module.exports = helperIseDeclarations;
19 changes: 19 additions & 0 deletions src/helperise/string_helpers/iye_oro.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Returns number of words in a string
*
* @returns {number}
*/
function iyeoro (args) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use lowerCamelCasing

if (Array.isArray(args)) {
let [ string, ] = args;

if (typeof string === "string") {
let split = string.split(" ");
return split.length;
}
throw new Error("Param must be a string");
}
throw new Error("Yorlang system error");
}

module.exports = iyeoro;
16 changes: 16 additions & 0 deletions src/helperise/string_helpers/okun_pin_si_orun.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* receives a string and returns an array using the optional limiter
* @returns array
*/
function pinoro (args) {
if (Array.isArray(args)) {
const [ string, limiter, ] = args;
if ((typeof string === "string")) {
return string.split(limiter || "");
}
throw new Error("Yorlang system error: arguments should be 2 strings");
}
throw new Error("Yorlang system error");
}

module.exports = pinoro;
16 changes: 16 additions & 0 deletions src/helperise/string_helpers/pipoto.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* @param {string} str - receives a string and returns the length
* @returns number
*/
function pipoto (args) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's already an helper method ka that does this

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existing helper function ka is to count number of elements in an array. This helper pipoto is to count the length of a string.

if (Array.isArray(args)) {
const [ string, ] = args;
if (typeof string === "string") {
return string.length;
}
throw new Error("Yorlang system error: arguments should be 1 string");
}
throw new Error("Yorlang system error");
}

module.exports = pipoto;