Created
April 17, 2022 06:43
-
-
Save MohamedGamil/878c160451280c684f5622e8409fc3db to your computer and use it in GitHub Desktop.
HackerRank / Grading Students
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const fs = require('fs'); | |
process.stdin.resume(); | |
process.stdin.setEncoding('utf-8'); | |
let inputString = ''; | |
let currentLine = 0; | |
process.stdin.on('data', function(inputStdin) { | |
inputString += inputStdin; | |
}); | |
process.stdin.on('end', function() { | |
inputString = inputString.split('\n'); | |
main(); | |
}); | |
function readLine() { | |
return inputString[currentLine++]; | |
} | |
/* | |
* Complete the 'gradingStudents' function below. | |
* | |
* The function is expected to return an INTEGER_ARRAY. | |
* The function accepts INTEGER_ARRAY grades as parameter. | |
*/ | |
function gradingStudents(grades) { | |
for (let idx in grades) { | |
const num = grades[idx]; | |
if (num < 38) { | |
continue; | |
} | |
const mod = Math.ceil(num / 5) * 5; | |
const diff = mod - num; | |
if (diff < 3) { | |
grades[idx] = mod; | |
} | |
} | |
return grades; | |
} | |
function main() { | |
const ws = fs.createWriteStream(process.env.OUTPUT_PATH); | |
const gradesCount = parseInt(readLine().trim(), 10); | |
let grades = []; | |
for (let i = 0; i < gradesCount; i++) { | |
const gradesItem = parseInt(readLine().trim(), 10); | |
grades.push(gradesItem); | |
} | |
const result = gradingStudents(grades); | |
ws.write(result.join('\n') + '\n'); | |
ws.end(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment