Skip to content

Instantly share code, notes, and snippets.

@bluepnume
Created May 13, 2021 07:00
Show Gist options
  • Save bluepnume/54cfd926f53a5c1e3dbe5995f91f4f38 to your computer and use it in GitHub Desktop.
Save bluepnume/54cfd926f53a5c1e3dbe5995f91f4f38 to your computer and use it in GitHub Desktop.
const calculateNewDifficulty = (headBlock : BlockType, previousHeadBlock : ?BlockType) : number => {
if (!previousHeadBlock) {
return headBlock.difficulty;
}
return (headBlock.time - previousHeadBlock.time) > BLOCK_TIME
? headBlock.difficulty - 1
: headBlock.difficulty + 1;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment