Skip to content

Instantly share code, notes, and snippets.

@Waltari10
Last active April 10, 2020 12:49
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 Waltari10/8aab7241b5f0df580490859fbc564d25 to your computer and use it in GitHub Desktop.
Save Waltari10/8aab7241b5f0df580490859fbc564d25 to your computer and use it in GitHub Desktop.
const heroLevelArr = [
2,
4,
6,
8,
11,
14,
17,
20,
24,
28,
32,
36,
41,
46,
51,
56,
62,
69,
76,
83,
90,
];
export const getHeroLevel = (exp = 0) => {
let level = 1;
if (!parseInt(exp) || isNaN(parseInt(exp))) {
return level;
}
heroLevelArr.forEach((threshold, index) => {
if (exp >= threshold) {
level = index + 1;
}
});
return level;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment