Skip to content

Commit

Permalink
add harishumasankar18_personal_org/detect-new-function.jsx
Browse files Browse the repository at this point in the history
  • Loading branch information
harish36000 authored and semgrep-bot committed Nov 27, 2024
1 parent af5f946 commit c019a4b
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions harishumasankar18_personal_org/detect-new-function.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

const calculate = (activity, health, weight, happiness) => {
return new Promise(async (resolve, reject) => {
try {
// devine formula :100:
let res = `with(a='${activity}', hp=${health}, w=${weight}, hs=${happiness}) {
if (a == 'feed') { hp += 1; w += 5; hs += 3; } if (a == 'play') { w -= 5; hp += 2; hs += 3; } if (a == 'sleep') { hp += 2; w += 3; hs += 3; } if ((a == 'feed' || a == 'sleep' ) && w > 70) { hp -= 10; hs -= 10; } else if ((a == 'feed' || a == 'sleep' ) && w < 40) { hp += 10; hs += 5; } else if (a == 'play' && w < 40) { hp -= 10; hs -= 10; } else if ( hs > 70 && (hp < 40 || w < 30)) { hs -= 10; } if ( hs > 70 ) { m = 'kissy' } else if ( hs < 40 ) { m = 'cry' } else { m = 'awkward'; } if ( hs > 100) { hs = 100; } if ( hs < 5) { hs = 5; } if ( hp < 5) { hp = 5; } if ( hp > 100) { hp = 100; } if (w < 10) { w = 10 } return {m, hp, w, hs}
}`;
quickMaths = new Function(res);
const {m, hp, w, hs} = quickMaths();
resolve({mood: m, health: hp, weight: w, happiness: hs})
}
catch (e) {
reject(e);
}
});
}

module.exports = {
calculate
}

0 comments on commit c019a4b

Please sign in to comment.