Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const sampleData = [
- [null, '<', '5', 'Buruk'],
- [null, '=', '5', 'Kurang'],
- ['6', '-', '10', 'Cukup'],
- [null, '>', '10', 'Bagus'],
- ];
- const selection = (value) => {
- const result = sampleData.filter((item) => {
- const operator = item[1];
- const input1 = item[0];
- const input2 = item[2];
- if (operator === '<') {
- return value < parseFloat(input2);
- } else if (operator === '=') {
- return value === parseFloat(input2);
- } else if (operator === '>') {
- return value > parseFloat(input2);
- } else if (operator === '-') {
- return value >= parseFloat(input1) && value <= parseFloat(input2);
- }
- });
- return result[0][3];
- }
- console.log('Result : ', selection(11));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement