Title: #1086 - High Five - LeetCode JavaScript Solutions
Open Graph Title: #1086 - High Five - LeetCode JavaScript Solutions
X Title: #1086 - High Five - LeetCode JavaScript Solutions
Description: Given a list of the scores of different students, items, where items[i] = [IDi, scorei] represents one score from a student with IDi, calcul...
Open Graph Description: Given a list of the scores of different students, items, where items[i] = [IDi, scorei] represents one score from a student with IDi, calcul...
X Description: Given a list of the scores of different students, items, where items[i] = [IDi, scorei] represents one score from a student with IDi, calcul...
Keywords:
Opengraph URL: https://leetcodejavascript.com/solutions/high-five
Domain: leetcodejavascript.com
{"@context":"https://schema.org","@type":"Code","url":"https://leetcodejavascript.com/solutions/high-five","name":"#1086 - High Five - LeetCode JavaScript Solutions","description":"Given a list of the scores of different students, items, where items[i] = [IDi, scorei] represents one score from a student with IDi, calcul...","programmingLanguage":"JavaScript","codeRepository":"https://github.com/JoshCrozier/leetcode-javascript","codeSampleType":"JavaScript","text":"/**\n * @param {number[][]} items\n * @return {number[][]}\n */\nvar highFive = function(items) {\n const studentScores = new Map();\n\n for (const [id, score] of items) {\n if (!studentScores.has(id)) {\n studentScores.set(id, []);\n }\n studentScores.get(id).push(score);\n }\n\n const result = [];\n for (const [id, scores] of studentScores) {\n scores.sort((a, b) => b - a);\n const topFiveSum = scores.slice(0, 5).reduce((sum, score) => sum + score, 0);\n const average = Math.floor(topFiveSum / 5);\n result.push([id, average]);\n }\n\n result.sort((a, b) => a[0] - b[0]);\n\n return result;\n};","keywords":"LeetCode 1086, #1086 - High Five, Easy, JavaScript solution","learningResourceType":"Code","isAccessibleForFree":true,"educationalLevel":"intermediate","interactivityType":"mixed"}
| author | LeetCodeJavascript.com |
| og:type | article |
| og:image | https://leetcodejavascript.com/og-image.jpg |
| og:site_name | LeetCode JavaScript Solutions |
| twitter:card | summary_large_image |
| twitter:url | https://leetcodejavascript.com/solutions/high-five |
| twitter:image | https://leetcodejavascript.com/og-image.jpg |
| twitter:creator | @joshcrozier |
| theme-color | #1f2937 |
Links:
| LeetCodeJavascript.com | https://leetcodejavascript.com/ |
| Star on GitHub | https://github.com/JoshCrozier/leetcode-javascript |
| Back to all solutions | https://leetcodejavascript.com |
| View on LeetCode | https://leetcode.com/problems/high-five/ |
| View on GitHub | https://github.com/JoshCrozier/leetcode-javascript/blob/master/solutions/1086-high-five.js |
| Array | https://leetcodejavascript.com/tags/array |
| Hash Table | https://leetcodejavascript.com/tags/hash-table |
| Sorting | https://leetcodejavascript.com/tags/sorting |
| Heap Priority Queue | https://leetcodejavascript.com/tags/heap-priority-queue |
| Josh Crozier | https://joshcrozier.com |
Viewport: width=device-width,initial-scale=1
Robots: index, follow