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

Max min branch #51

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Conversation

Harjacober
Copy link

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

var max = o_tobi_julo(34, 22, 56, 24, 4)
max = 56
var min= o_kere_julo(34, 22, 56, 24, 4)
min= 4
var min= o_kere_julo([34, 22, 56, 24, 4])
min= 4
var max= o_kere_julo([34, 22, 56, 24, 4], 45, 545, 45, 445)
max= 56
all other arguments are ignored only the first array argument is recognized

@Harjacober
Copy link
Author

it should be note that var in the code snippets will be replaced with jeki if to be used in Yorlang

@Mastersam07
Copy link

i thought variable declarations are done with jeki not var ?

@Mastersam07
Copy link

it should be note that var in the code snippets will be replaced with jeki if to be used in Yorlang

okay.

@anoniscoding
Copy link
Owner

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";
Copy link
Owner

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

Copy link
Author

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

Copy link
Author

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

Copy link
Author

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 "";
Copy link
Owner

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 () {
Copy link
Owner

@anoniscoding anoniscoding Dec 20, 2018

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 () {
Copy link
Owner

@anoniscoding anoniscoding Dec 20, 2018

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 @@
/**
Copy link
Owner

@anoniscoding anoniscoding Jan 1, 2019

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 and blah 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 to var 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 with eyiToTobiJu(1,2,3) will result in the args value being [1,2,3]. Likewise, calling an helper function in yorlang with eyiToTobiJu([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 number
  • Math.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 of args is an array using Array.isArray(args[0])

@@ -0,0 +1,26 @@
/**
Copy link
Owner

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 to var 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 with eyiToKereJu(1,2,3) will result in the args value being [1,2,3]. Likewise, calling an helper function in yorlang with eyiToKereJu([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 number
  • Math.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 of args is an array using Array.isArray(args[0])

@Harjacober
Copy link
Author

Hey @anoniscoding I followed the guidelines you gave above and updated the helperise eyiToKereJu and eyiToTobiJu and I deleted the file you asked me to. Kindly review again. Thanks

* note that if the first argument is an array, all other arguments are neglected
* @returns {[number]} minimumNumber
*/
function eyiToKereJu () {
Copy link
Owner

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

Copy link
Owner

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

@Harjacober
Copy link
Author

I optimized the functions, I added more test cases as you requested and I registered the two helper functions at registeredHelperise.js which is now causing conflict. Kindly review again. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants