Todorov_Stanimir

04. Radio Crystals Functions - More Exercise

Jun 9th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function radioCrystal(input) {
  2.     let targetThickness = input.shift();
  3.     for (let i = 0; i < input.length; i++) {
  4.         thickness = input[i];
  5.  
  6.         console.log(`Processing chunk ${thickness} microns`);
  7.  
  8.         if (thickness / 4 >= targetThickness) {
  9.             let counter = 0
  10.             while (thickness / 4 >= targetThickness) {
  11.                 counter++;
  12.                 thickness = thickness / 4;
  13.             }
  14.             console.log(`Cut x${counter}`);
  15.             console.log('Transporting and washing');
  16.             thickness = parseInt(thickness);
  17.         }
  18.         if (thickness - 0.2 * thickness >= targetThickness) {
  19.             let counter = 0
  20.             while ((thickness - 0.2 * thickness) >= targetThickness) {
  21.                 counter++;
  22.                 thickness -= 0.2 * thickness;
  23.             }
  24.             console.log(`Lap x${counter}`);
  25.             console.log('Transporting and washing');
  26.             thickness = parseInt(thickness);
  27.         }
  28.         if (thickness - 20 >= targetThickness) {
  29.             let counter = 0
  30.             while ((thickness - 20) >= targetThickness) {
  31.                 counter++;
  32.                 thickness -= 20;
  33.             }
  34.             console.log(`Grind x${counter}`);
  35.             console.log('Transporting and washing');
  36.             thickness = parseInt(thickness);
  37.         }
  38.         if (thickness - 2 >= targetThickness) {
  39.             let counter = 0
  40.             while ((thickness - 2) >= (targetThickness - 1)) {
  41.                 counter++;
  42.                 thickness -= 2;
  43.             }
  44.             console.log(`Etch x${counter}`);
  45.             console.log('Transporting and washing');
  46.             thickness = parseInt(thickness);
  47.         }
  48.         if (thickness + 1 === targetThickness) {
  49.             thickness += 1;
  50.             console.log('X-ray x1');
  51.         }
  52.         console.log(`Finished crystal ${thickness} microns`);
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment