'end_PWM' is never reassigned. Use 'const' instead
202 PWM_values.push(Math.round(uL_table[i + 1])); // Add rounded PWM value to PWM_values list for record keeping and debugging
203 console.log(end_PWM); //////////// Send pump number and rounded PWM value to arduino
204 } else {
205 let end_PWM = Math.round(uL_table[i + 3]); // used for PWM tracking206 }
207 }
208 // If normal step
'end_PWM' is never reassigned. Use 'const' instead
198 // If last step
199 if (Math.abs(uL_table[i] - goal_uL) < Math.abs(uL_table[i + 2] - goal_uL)) {
200 // if this uL value from uL_table is closer to goal_uL than the previous one
201 let end_PWM = Math.round(uL_table[i + 1]); // used for PWM tracking202 PWM_values.push(Math.round(uL_table[i + 1])); // Add rounded PWM value to PWM_values list for record keeping and debugging
203 console.log(end_PWM); //////////// Send pump number and rounded PWM value to arduino
204 } else {
'end_PWM' is never reassigned. Use 'const' instead
179 PWM_values.push(Math.round(uL_table[i + 1])); // Add rounded PWM value to PWM_values list for record keeping and debugging
180 //console.log(end_PWM); //////////// Send pump number and rounded PWM value to arduino
181 } else {
182 let end_PWM = Math.round(uL_table[i - 1]); // used for PWM tracking183 }
184 }
185 // If normal step
'end_PWM' is never reassigned. Use 'const' instead
175 // If last step
176 if (Math.abs(uL_table[i] - goal_uL) < Math.abs(uL_table[i - 2] - goal_uL)) {
177 // if this uL value from uL_table is closer to goal_uL than the previous one
178 let end_PWM = Math.round(uL_table[i + 1]); // used for PWM tracking179 PWM_values.push(Math.round(uL_table[i + 1])); // Add rounded PWM value to PWM_values list for record keeping and debugging
180 //console.log(end_PWM); //////////// Send pump number and rounded PWM value to arduino
181 } else {
'PWM_values' is never reassigned. Use 'const' instead
165
166 // Iterate through uL_table from next uL_index and go specified number of steps
167 // MUST DELAY each console.log by the letiable 'seconds_per_step'
168 let PWM_values = []; // Used to keep track of PWM steps to move, for record keeping and debugging169 if (going_up_uL) {
170 // if increasing in uL from current_uL to goal_uL
171 for (let i = first_uL_index; i <= goal_uL_index; i = i + 2) {
'going_up_uL' is never reassigned. Use 'const' instead
125
126 // Find current place and goal place in uL_table
127 let f_found = false; // set to true when the first_uL_index is found to avoid this if statment through rest of loop
128 let going_up_uL = goal_uL - current_uL > 0;129 let first_uL_index = 0;
130 let goal_uL_index = 0;
131
'seconds_per_step' is never reassigned. Use 'const' instead
121
122 // Get number of steps per second and number of seconds per step
123 let steps_per_second = num_steps / time_sec; // send to user, not used in program
124 let seconds_per_step = time_sec / num_steps; // needed for delay between step125
126 // Find current place and goal place in uL_table
127 let f_found = false; // set to true when the first_uL_index is found to avoid this if statment through rest of loop
'steps_per_second' is never reassigned. Use 'const' instead
120 let num_steps = uL_to_dispense / uL_precision;
121
122 // Get number of steps per second and number of seconds per step
123 let steps_per_second = num_steps / time_sec; // send to user, not used in program124 let seconds_per_step = time_sec / num_steps; // needed for delay between step
125
126 // Find current place and goal place in uL_table
'num_steps' is never reassigned. Use 'const' instead
117 let uL_to_dispense = Math.abs(goal_uL - current_uL);
118
119 // Get Total number of steps
120 let num_steps = uL_to_dispense / uL_precision;121
122 // Get number of steps per second and number of seconds per step
123 let steps_per_second = num_steps / time_sec; // send to user, not used in program
'uL_to_dispense' is never reassigned. Use 'const' instead
114
115export function even_uL_steps(uL_table, PWM_table, uL_precision, current_uL, goal_uL, time_sec) {
116 // Get uL_to_dispense
117 let uL_to_dispense = Math.abs(goal_uL - current_uL);118
119 // Get Total number of steps
120 let num_steps = uL_to_dispense / uL_precision;
'uL_dic' is never reassigned. Use 'const' instead
54
55 // create uL_table
56 let uL_table = [];
57 let uL_dic = {}; 58 for (let uLValue = uL_min; uLValue < uL_range + uL_min + uL_precision; uLValue = uLValue + uL_precision) {
59 // From uL_min (a given) to uL_min+uL_range! uL_precision added on to allow last uL value to be iterated through. Increase by steps of uL_precision
60 // rename i (which is current uL value)
'uL_table' is never reassigned. Use 'const' instead
53 }
54
55 // create uL_table
56 let uL_table = []; 57 let uL_dic = {};
58 for (let uLValue = uL_min; uLValue < uL_range + uL_min + uL_precision; uLValue = uLValue + uL_precision) {
59 // From uL_min (a given) to uL_min+uL_range! uL_precision added on to allow last uL value to be iterated through. Increase by steps of uL_precision
'uL_diff_prev' is never reassigned. Use 'const' instead
45
46 // Find uL_precision by finding the max uL difference between PWM values.
47 let uL_diff = PWM_table[PWM_table.length - 1] - PWM_table[PWM_table.length - 3];
48 let uL_diff_prev = PWM_table[PWM_table.length - 3] - PWM_table[PWM_table.length - 5]; 49 if (uL_diff < uL_diff_prev && not_found) {
50 uL_precision = Math.round(uL_diff_prev * 100) / 100;
51 not_found = false;
'uL_diff' is never reassigned. Use 'const' instead
44 PWM_dic[i] = uL_temp;
45
46 // Find uL_precision by finding the max uL difference between PWM values.
47 let uL_diff = PWM_table[PWM_table.length - 1] - PWM_table[PWM_table.length - 3]; 48 let uL_diff_prev = PWM_table[PWM_table.length - 3] - PWM_table[PWM_table.length - 5];
49 if (uL_diff < uL_diff_prev && not_found) {
50 uL_precision = Math.round(uL_diff_prev * 100) / 100;
'uL_temp' is never reassigned. Use 'const' instead
38 // From PWM_min value to PWM_max value
39 PWM_table.push(i); // Add current PWM value to PWM_table
40 let mL_temp = mL_max - (r * Math.cos(PWM2rad(i)) + Math.sqrt(Math.pow(b, 2) - Math.pow(r * Math.sin(PWM2rad(i)) + d, 2)) - X_min) / a; // Calculate mL value with formula of motion
41 let uL_temp = Math.round(mL_temp * 100000) / 100; // convert to uL and round to first decimal place 42 PWM_table.push(uL_temp); // Add uL value to PWM_table
43
44 PWM_dic[i] = uL_temp;
'mL_temp' is never reassigned. Use 'const' instead
37 for (let i = PWM_MIN; i <= PWM_MAX; i++) {
38 // From PWM_min value to PWM_max value
39 PWM_table.push(i); // Add current PWM value to PWM_table
40 let mL_temp = mL_max - (r * Math.cos(PWM2rad(i)) + Math.sqrt(Math.pow(b, 2) - Math.pow(r * Math.sin(PWM2rad(i)) + d, 2)) - X_min) / a; // Calculate mL value with formula of motion 41 let uL_temp = Math.round(mL_temp * 100000) / 100; // convert to uL and round to first decimal place
42 PWM_table.push(uL_temp); // Add uL value to PWM_table
43
'PWM_dic' is never reassigned. Use 'const' instead
30
31 // Create PWM_table and find uL_precision
32 let PWM_table = []; // used in this inner function
33 let PWM_dic = {}; // passed as output to easily hash 34 let uL_precision = 0;
35
36 let not_found = true;
'PWM_table' is never reassigned. Use 'const' instead
29 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
30
31 // Create PWM_table and find uL_precision
32 let PWM_table = []; // used in this inner function 33 let PWM_dic = {}; // passed as output to easily hash
34 let uL_precision = 0;
35
'uL_range' is never reassigned. Use 'const' instead
24 let uL_min = mL_min * 1000; // convert incoming letiables from mL to uL
25 let uL_max = mL_max * 1000;
26 let mL_range = mL_max - mL_min;
27 let uL_range = mL_range * 1000; // convert incoming letiables from mL to uL 28
29 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
30
'mL_range' is never reassigned. Use 'const' instead
23 let mL_max = mL_min + (X_max - X_min) / a; // Calculate mLmax by S
24 let uL_min = mL_min * 1000; // convert incoming letiables from mL to uL
25 let uL_max = mL_max * 1000;
26 let mL_range = mL_max - mL_min; 27 let uL_range = mL_range * 1000; // convert incoming letiables from mL to uL
28
29 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
'uL_max' is never reassigned. Use 'const' instead
22 let mL_min = 0; // Default value for mLmax, initalized by user in Assembly step. MUST be true
23 let mL_max = mL_min + (X_max - X_min) / a; // Calculate mLmax by S
24 let uL_min = mL_min * 1000; // convert incoming letiables from mL to uL
25 let uL_max = mL_max * 1000; 26 let mL_range = mL_max - mL_min;
27 let uL_range = mL_range * 1000; // convert incoming letiables from mL to uL
28
'uL_min' is never reassigned. Use 'const' instead
21 let X_min = displacement(theta_max, r, b, d, a); // Calculate Xmin by plugging in theta_max to displacement function
22 let mL_min = 0; // Default value for mLmax, initalized by user in Assembly step. MUST be true
23 let mL_max = mL_min + (X_max - X_min) / a; // Calculate mLmax by S
24 let uL_min = mL_min * 1000; // convert incoming letiables from mL to uL 25 let uL_max = mL_max * 1000;
26 let mL_range = mL_max - mL_min;
27 let uL_range = mL_range * 1000; // convert incoming letiables from mL to uL
'mL_max' is never reassigned. Use 'const' instead
20 let X_max = displacement(theta_min, r, b, d, a); // Calculate Xmax by plugging in theta_min to displacement function
21 let X_min = displacement(theta_max, r, b, d, a); // Calculate Xmin by plugging in theta_max to displacement function
22 let mL_min = 0; // Default value for mLmax, initalized by user in Assembly step. MUST be true
23 let mL_max = mL_min + (X_max - X_min) / a; // Calculate mLmax by S 24 let uL_min = mL_min * 1000; // convert incoming letiables from mL to uL
25 let uL_max = mL_max * 1000;
26 let mL_range = mL_max - mL_min;
'mL_min' is never reassigned. Use 'const' instead
19 let theta_max = thetaXArray[displacementArray.indexOf(displacement_min)]; // Calculate theta_max by pulling theta value from theta array at the index where the displacement min was found
20 let X_max = displacement(theta_min, r, b, d, a); // Calculate Xmax by plugging in theta_min to displacement function
21 let X_min = displacement(theta_max, r, b, d, a); // Calculate Xmin by plugging in theta_max to displacement function
22 let mL_min = 0; // Default value for mLmax, initalized by user in Assembly step. MUST be true 23 let mL_max = mL_min + (X_max - X_min) / a; // Calculate mLmax by S
24 let uL_min = mL_min * 1000; // convert incoming letiables from mL to uL
25 let uL_max = mL_max * 1000;
'X_min' is never reassigned. Use 'const' instead
18 let theta_min = thetaXArray[displacementArray.indexOf(displacement_max)]; // Calculate theta_min by pulling theta value from theta array at the index where the displacement max was found
19 let theta_max = thetaXArray[displacementArray.indexOf(displacement_min)]; // Calculate theta_max by pulling theta value from theta array at the index where the displacement min was found
20 let X_max = displacement(theta_min, r, b, d, a); // Calculate Xmax by plugging in theta_min to displacement function
21 let X_min = displacement(theta_max, r, b, d, a); // Calculate Xmin by plugging in theta_max to displacement function 22 let mL_min = 0; // Default value for mLmax, initalized by user in Assembly step. MUST be true
23 let mL_max = mL_min + (X_max - X_min) / a; // Calculate mLmax by S
24 let uL_min = mL_min * 1000; // convert incoming letiables from mL to uL
Description
Variables that are never re-assigned a new value after their initial declaration should be declared with the const
keyword.
This prevents the programmer from erroneously re-assigning to a read-only variable, and informs those reading the code that a variable is a constant value.
Bad Practice
let pi = Math.PI
for (let x of xs) {
use(x);
}
let { a, b } = object;
use(a, b);
Recommended
const pi = Math.PI
for (const x of xs) {
use(x);
}
const { a, b } = object;
use(a, b);