Created
September 6, 2021 15:03
-
-
Save robinmollah/f91787099ae5a895a0117a995c65bbf0 to your computer and use it in GitHub Desktop.
Calculates cost from text: https://www.linkedin.com/posts/robinmollah_scriptwriting-javascript-productivity-activity-6785840697766498304-asBl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* In this video, you will be able to see the code that automates calculation of selected text | |
* https://www.linkedin.com/posts/robinmollah_scriptwriting-javascript-productivity-activity-6785840697766498304-asBl | |
/* | |
function run(input, parameters) { | |
if(input.length == 0) input.push("robin +11tk\\nrobin +11tk"); | |
let output = input[0].split("\n"); | |
let sum = 0; | |
for(let line of output){ | |
let match = line.match(/(\+|\-)(\d+)(K|tk|BDT|USD?)/i); | |
if(match){ | |
let number = match[3] == "USD" ? parseInt(match[2]) * 85 : parseInt(match[2]); | |
if(match[1] == '+'){ | |
sum += number; | |
} else if (match[1] == '-'){ | |
sum -= number; | |
} else { | |
console.log("Invalid operator"); | |
} | |
} | |
} | |
console.log(`Total: ${sum} Taka`); | |
return `Total: ${sum} Taka`; | |
} | |
run(input); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment