Retired

// (retired)

Description
Loading description...
Algorithms
Arrays
Data Types
Fundamentals
  • Please sign in or sign up to leave a comment.
  • JohanWiltink Avatar

    Random tests can generate [] as an input.

  • JohanWiltink Avatar

    This is a problem.

    You can't use normal equality with floating point values ( and rounding is not going to be a solution ); you have to allow an error margin. Write your own wrapper specific for your output encoding ( which is also bad, bad, bad ).

  • JohanWiltink Avatar
    input: [4,1,3,5]
    expected [ 3.25, 3 ] to deeply equal [ 3.25, null ]
    

    When do we return a nested array ( [1,3,4,5] ) and when do we return null ? I actually see no problem with multiple modes - arrays are not limited in length and 1,3,4,5 are all occurring equally often.

    • FurgieWurgie Avatar

      In the discription I was doing it in such a way that if all the numbers were the same frequency and none were more than the other then return null. should I do it differently?

    • user9644768 Avatar

      I think

      when the length of the input is not 1
          if there are no duplicate in the array
              then you've to return 'null'
          otherwise
              if multiple element have same max count
                  return array consisting of all of them
              other
                  return the number with max count
      
      otherwise
        return the first element
      
    • FurgieWurgie Avatar

      I've changed the description

      Question marked resolved by FurgieWurgie 4 years ago
    • JohanWiltink Avatar

      I solved it by requiring the frequency of the mode having to be > 1. That doesn't make much sense.

      The description is too long anyway. Simplify things ( a lot ), and take out any such logical inconsistencies. There is always a mode ( unless the input is [] ). ( Is that tested? No, it doesn't have a mean either. This should be specified. )

    • JohanWiltink Avatar

      You fixed it wrong. Well, less than ideal.

      If you're wrapping one block in describe, wrap all blocks in describe, or chai will reorder and format your tests in weird ways.

      You can nest its in describes and describes in describes, but not describes in its or its in its. The outermost level of wrapping can be its ( if it's the only level ); the innermost level must be. There is no need to show the input in the header anyway ( people can debug print that themselves if they need to ), so use wrappers to group tests, not to show endless useless information. ( Other opinions may be available, but I favour a rather minimalistic look of test results. )

  • JohanWiltink Avatar

    Returning inconsistent datatypes is not a best practice.

  • JohanWiltink Avatar

    Not raising an Issue without a specific example, but mean and mode have been done before. This feels like a duplicate.

    • JohanWiltink Avatar

      OK, realistically, this is going to be retired sooner rather than later.

      Your next attempt at publishing a kata should really have less problems - preferably none at all - when you hit Publish. Read the docs; if you don't know something, ask for help before publishing ( docs say where ), and don't cut any corners. Also, pick an original subject for your kata. Or the next one will probably get retired again, which is good for no one.

  • JohanWiltink Avatar

    Node v8.1.3

    Why use an obsolescent version?

    You are even already using chai!