-
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
Max min branch #51
base: master
Are you sure you want to change the base?
Max min branch #51
Conversation
it should be note that |
i thought variable declarations are done with |
okay. |
Please add test cases for your code before i leave a review |
sample/maxmin.yl
Outdated
@@ -0,0 +1,19 @@ | |||
sope "eleyi a fun wa ni nomba to tobi julo"; |
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.
Hey bro. Check the test/helpers/ folder to see samples of how test cases were written for other helper functions
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.
Alright I will do that now
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.
Oh! my bad.... Didn't know that was the test you were talking about. I will do that now
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.
@anoniscoding I created test cases already, 3 for each classes, kindly review
sample/maxmin.yl
Outdated
@@ -0,0 +1,19 @@ | |||
sope "eleyi a fun wa ni nomba to tobi julo"; | |||
sope ""; |
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 delete this file.
* note that if the first argument is an array, all other arguments are neglected | ||
* @returns {[number]} minimumNumber | ||
*/ | ||
function oKereJulo () { |
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.
i'll prefer you rename it to eyiToKereJu
* note that if the first argument is an array, all other arguments are neglected | ||
* @returns {[number]} maximumNumber | ||
*/ | ||
function oTobiJulo () { |
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.
I'll prefer you rename it eyiToTobiJu
@@ -0,0 +1,26 @@ | |||
/** |
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.
Helper ise methods in yorlang have a parameter args that is of type array.
So in this case , we should have function eyiToTobiJu(args)
. You can reference other helper functions in the codebase to see how this has been applied
The spec for eyiToTobiJu is as follows:
- it should be able to take comma separated values that are of type number i.e
eyiToTobiJu(1,2,3)
- It should be able to take an array as its value i.e
eyiToTobiJu([1,2,3])
.
Edge cases:
- Whenever it takes an array as its value, other parameters after the array shall be ignored i.e
eyiToTobiJu([1,2,3], 4, "blah")
.4
andblah
in this case will be ignored.eyiToTobiJu
will only attempt to find the maximum of the array[1,2,3]
. - In the event that a non number value is passed in the parameter list e.g
eyiToTobiJu(1,2,"blah")
, the function should throw an error
Notes:
- There's a utility function Array.isArray() in es6
- Use const whenever you're not mutating the value of a variable
- Please prefer
let
tovar
whenever you're mutating the value of variable args
variable is an array of all the parameters passed to an helper function. For example, calling an helper function in yorlang witheyiToTobiJu(1,2,3)
will result in the args value being[1,2,3]
. Likewise, calling an helper function in yorlang witheyiToTobiJu([1,2,3])
will result in the args value being[[1,2,3]]
Math.max(...args)
in the event that all values in args are numbers will return the minimum numberMath.max(...args)
in the event that all values in args are not numbers will return NaN- Throw an error when the result of Math.max is NaN
- To cater for cases where
eyiToTobiJu
can take an array as parameter, check if the first value ofargs
is an array usingArray.isArray(args[0])
@@ -0,0 +1,26 @@ | |||
/** |
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.
Helper ise methods in yorlang have a parameter args that is of type array.
So in this case , we should have function eyiToKereJu(args)
The spec for eyiToKereJu is as follows:
- it should be able to take comma separated values that are of type number i.e
eyiToKereJu(1,2,3)
- It should be able to take an array as its value i.e
eyiToKereJu([1,2,3])
Edge cases:
- Whenever it takes an array as its value, other parameters after the array shall be ignored i.e
eyiToKereJu([1,2,3], 4, "blah")
. 4 and blah in this case will be ignored. eyiToKereJu will only attempt to find the minimum of the array [1,2,3]. - In the event that a non number value is passed in the parameter list e.g
eyiToKereJu(1,2,"blah")
, the function should throw an error
Notes:
- There's a utility function Array.isArray() in es6
- Use const whenever you're not mutating the value of a variable
- Please prefer
let
tovar
whenever you're mutating the value of variable args
variable is an array of all the parameters passed to an helper function. For example, calling an helper function in yorlang witheyiToKereJu(1,2,3)
will result in the args value being[1,2,3]
. Likewise, calling an helper function in yorlang witheyiToKereJu([1,2,3])
will result in the args value being[[1,2,3]]
Math.min(...args)
in the event that all values in args are numbers will return the minimum numberMath.min(...args)
in the event that all values in args are not numbers will return NaN- Throw an error when the result of Math.max is NaN
- To cater for cases where
eyiToKereJu
can take an array as parameter, check if the first value ofargs
is an array usingArray.isArray(args[0])
Hey @anoniscoding I followed the guidelines you gave above and updated the helperise |
* note that if the first argument is an array, all other arguments are neglected | ||
* @returns {[number]} minimumNumber | ||
*/ | ||
function eyiToKereJu () { |
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.
Following the guidelines, you could have
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")
}
The above covers all the edge cases where args can be either of the following
- [1,2,43]
- [[3,2,34]]
- [1,"blah",2]
- [[32,4,5], "blah", "2"]
Please make sure your test cases covers each of these possible values that could be passed to eyiToKereJu
The above information also applies to eyiToTobiJu
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.
You must also register your helper functions in the file named registeredHelperIse.js
I optimized the functions, I added more test cases as you requested and I registered the two helper functions at |
Adds Maximum and Minimum helper functions
o_kere_julo(Minimum)
o_kere_julo returns the minimum number in a list of numbers
o_tobi_julo(Maximum)
o_tobi_julo returns the maximum number in a list of numbers
both functions takes an array or numbers separated by a ',' as argument
if the first argument is an array, the function automatically ignores the other arguments and computes the max or min number in the first argument array.
Usage