-
Notifications
You must be signed in to change notification settings - Fork 70
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** Takes any number | ||
* Returns absolute value of number | ||
* | ||
* @returns {number} | ||
*/ | ||
function nombalasan (args) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use camel casing. |
||
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; |
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use camel casing. square root is
|
||
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; |
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
var result = ""; | ||
var characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; | ||
var charactersLength = characters.length; | ||
for (var i = 0; i < length; i++) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use |
||
result += characters.charAt(Math.floor(Math.random() * charactersLength)); | ||
} | ||
return result; | ||
} | ||
throw new Error("Yorlang system error"); | ||
} | ||
|
||
module.exports = yipooro; |
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; |
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; |
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's already an helper method There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The existing helper function |
||
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; |
There was a problem hiding this comment.
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