Advertisement
Guest User

Untitled

a guest
Aug 12th, 2021
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function calcCost(data) {
  2.     const [
  3.         tariffCost,
  4.         trafficLimit,
  5.         extraMegabyteCost,
  6.         spentTraffic
  7.     ] = data.toString().trim().split(/\s+/).map(Number);
  8.  
  9.     if (trafficLimit >= spentTraffic) return tariffCost;
  10.  
  11.     return tariffCost + extraMegabyteCost * (spentTraffic - trafficLimit);
  12. }
  13.  
  14.  
  15. var readline = require('readline');
  16. var rl = readline.createInterface({
  17.     input: process.stdin,
  18.     output: process.stdout
  19. });
  20.  
  21. let result = 0;
  22.  
  23. process.stdin.on('end', () => {
  24.     console.log(result);
  25.     process.exit(0);
  26. });
  27.  
  28. rl.on('line', function (data) {
  29.     result = calcCost(data);
  30. });
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement