Sort by

recency

|

3978 Discussions

|

  • + 0 comments

    Typescript:

    let result: number[] = [];
    
    for (let i of grades) {
       if (i < 38) {
          result.push(i);
       } else {
          if ((i + 2) % 5 == 0) {
                result.push(i + 2);
          } else if ((i + 1) % 5 == 0) {
                result.push(i + 1);
          } else {
                result.push(i);
          }
       }
    }
    
    return result;
    
  • + 0 comments

    Go func

    var res []int32
        for _, i := range grades {
            if i >= 38 {
                if i%5 < 3 { // i habis di bagi 5 sisa kurang dari 3 output i
                    res = append(res, i)
                    fmt.Println(i, "value index angka kurang dari 3")
                } else {
                    //perhitungan penambahan pembulatan
                    akumulate := 5 - (i % 5) // 5 dikurang operasi bilangan i value habis di bagi 5
                    res = append(res, (i + akumulate))
                    fmt.Println(i, "value index angka lebih dari 3")
                }
            } else {
                res = append(res, i)
                fmt.Println(i, "less than 38")
            }
        }
        return res
    
  • + 0 comments

    in typescript

    const finalGrade: number[] = [] for(let i = 0; i < grades.length; i++) { const newNote = Math.ceil(grades[i] / 5) * 5 const isNewNote = newNote - grades[i] < 3 ? true : false if(grades[i] < 38 || !isNewNote) { finalGrade.push(grades[i]) } else if(isNewNote) { finalGrade.push(newNote) } } return finalGrade

  • + 0 comments
    def gradingStudents(grades):
       
        li = []
        for i in grades:
            if i < 38:
                li.append(i)
            else:
                if (i+2)%5==0 :
                     li.append(i+2)
                elif (i+1)%5==0:
                    li.append(i+1)
                else:
                    li.append(i)
        return li
    
  • + 0 comments
        rounded_grades = []
        for grade in grades:
            if grade >= 38:
                remainder = grade % 5
                multiple5 = grade + (5 - remainder)
                if multiple5 - grade < 3:
                    grade = multiple5
            rounded_grades.append(grade)
        return rounded_grades