Move History

Rooted by: Is Greater Than?
Fork Selected
  • Fundamentals
    Logic
    Description

    And even more by removing the foreach bracket, writing System.IComparable instead of writing "using System" at the beggining and removing the useless "public" before the class declaration

    Code
    class Math{public static T Max<T>(params T[]p)where T:System.IComparable<T>{foreach(T a in p)p[0]=p[0].CompareTo(a)<0?a:p[0];return p[0];}}
    Test Cases
    namespace Solution {
    using NUnit.Framework;
    
      [TestFixture]
      public class SolutionTest
      {
        
            [Test]
            [TestCase(1,2,2)]
            [TestCase(2,1,2)]
            [TestCase(1,1,1)]
            public void Max_WhenCalled_ReturnTheGreaterArgument(int a, int b, int expectedResult)
            {
                var result = Math.Max(a,b);
    
                Assert.That(result, Is.EqualTo(expectedResult));
            }
      }
    }
  • Code
    • using System;public class Math{public static T Max<T>(params T[]p)where T:IComparable<T>{foreach(T a in p){p[0]=p[0].CompareTo(a)<0?a:p[0];}return p[0];}}
    • class Math{public static T Max<T>(params T[]p)where T:System.IComparable<T>{foreach(T a in p)p[0]=p[0].CompareTo(a)<0?a:p[0];return p[0];}}