Ad

I wrote it in 3 lines

Code
Diff
  • getGrade=function(a,b,c){
      if(((a+b+c)/3)<60){return "F"}
      const alphabets = [...Array(26)].map((_, i) => String.fromCharCode(97 + i));
      return alphabets[Math.floor((9-Math.floor(((a+b+c)/3)/10)))].toUpperCase();
    
    }
    • const grades = [[90, 'A'], [80, 'B'], [70, 'C'], [60, 'D']]
    • const getGrade = (...ss) => {
    • const score = ss.reduce((a,b) => a+b) / ss.length
    • return grades.find(([s, g]) => score >= s)?.at(1) || 'F'
    • getGrade=function(a,b,c){
    • if(((a+b+c)/3)<60){return "F"}
    • const alphabets = [...Array(26)].map((_, i) => String.fromCharCode(97 + i));
    • return alphabets[Math.floor((9-Math.floor(((a+b+c)/3)/10)))].toUpperCase();
    • }
Code
Diff
  • def sum(arr):
        sum = 0
        for m in range(0,2):
            for a in range(0,2):
                for j in range(0,2):
                    for e in range(0,2):
                        for s in range(0,2):
                            for t in range(0,2):
                                for i in arr:
                                    for c in range(i):
                                        sum+=1
        print(sum)
        string="majestic"
        d=1
        for x in string:
            d=d*2
        return int(sum/(d/4))
    • def sum(arr):
    • if not arr:
    • return 0
    • return arr[len(arr)-1]+sum(arr[:-1])
    • sum = 0
    • for m in range(0,2):
    • for a in range(0,2):
    • for j in range(0,2):
    • for e in range(0,2):
    • for s in range(0,2):
    • for t in range(0,2):
    • for i in arr:
    • for c in range(i):
    • sum+=1
    • print(sum)
    • string="majestic"
    • d=1
    • for x in string:
    • d=d*2
    • return int(sum/(d/4))
Code
Diff
  • def sum(arr):
        if not arr:
            return 0
        return arr[len(arr)-1]+sum(arr[:-1])
    • def sum(arr):
    • if not arr:
    • return 0
    • return arr[0] + sum(arr[1:])
    • return arr[len(arr)-1]+sum(arr[:-1])