Skip to content

Instantly share code, notes, and snippets.

@hydai
Created September 21, 2020 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hydai/1fc00629951108a31993a03b48f41158 to your computer and use it in GitHub Desktop.
Save hydai/1fc00629951108a31993a03b48f41158 to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.1;
contract StudentScores {
mapping(string => uint) scores;
string[] names;
function addScore(string memory name, uint score) public {
scores[name] = score;
names.push(name);
}
function getScore(string memory name) public view returns (uint) {
return scores[name];
}
function clear() public {
while (names.length > 0) {
delete scores[names[names.length-1]];
names.pop();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment