Advertisement
Aguezz

SISI - PROCSI - auto calculate passing grade

Oct 10th, 2022
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. const sampleData = [
  2. [null, '<', '5', 'Buruk'],
  3. [null, '=', '5', 'Kurang'],
  4. ['6', '-', '10', 'Cukup'],
  5. [null, '>', '10', 'Bagus'],
  6. ];
  7.  
  8. const selection = (value) => {
  9. const result = sampleData.filter((item) => {
  10. const operator = item[1];
  11.  
  12. const input1 = item[0];
  13. const input2 = item[2];
  14.  
  15. if (operator === '<') {
  16. return value < parseFloat(input2);
  17. } else if (operator === '=') {
  18. return value === parseFloat(input2);
  19. } else if (operator === '>') {
  20. return value > parseFloat(input2);
  21. } else if (operator === '-') {
  22. return value >= parseFloat(input1) && value <= parseFloat(input2);
  23. }
  24. });
  25. return result[0][3];
  26.  
  27. }
  28.  
  29. console.log('Result : ', selection(11));
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement