Skip to content

Commit

Permalink
created $and
Browse files Browse the repository at this point in the history
  • Loading branch information
baka-aho authored Dec 30, 2023
1 parent 176ed33 commit 06754de
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/functions/misc/and.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module.exports = (d) => {
const data = d.util.aoiFunc(d);
if (data.err) return d.error(data.err);

const conditions = data.inside.splits.map(c => c.trim());

function evaluateAND(conditions) {

return conditions.reduce((prev, current) => {

let result;

const [left, comparator, right] = current.split(/(==|!=|>=|<=|>|<)/);

if (comparator === '==') {
result = left === right;
} else if (comparator === '!=') {
result = left !== right;
} else if (comparator === '<=') {
result = parseFloat(left) <= parseFloat(right);
} else if (comparator === '>=') {
result = parseFloat(left) >= parseFloat(right);
} else if (comparator === '>') {
result = parseFloat(left) > parseFloat(right);
} else if (comparator === '<') {
result = parseFloat(left) < parseFloat(right);
}

return prev && result;

}, true);

}

data.result = evaluateAND(conditions);
return {
code: d.util.setCode(data)
};
}

0 comments on commit 06754de

Please sign in to comment.