For loop to simplify code
I'm trying to work out how I can write this code more efficiently. I'm thinking it should be possible to 'wrap' it in a 'for loop', but I can figure out how to assign each iteration ( i = 9 to i = 12) to the 'multiplier' and then to get the related code to apply to the relevant iteration?
- for(i = 9; i < 13; i++)
- if(multiplier == 9) {
- middleArray.pop();
- middleArray.push('0');
- }
- if(multiplier == 10) {
- for(i = 1; i < 3; i++) {
- middleArray.pop();
- }
- middleArray.push('1', '2');
- }
- if(multiplier == 11) {
- for(i = 1; i < 4; i++) {
- middleArray.pop();
- }
- middleArray.push('1', '2', '3');
- }
- if(multiplier == 12) {
- for(i = 1; i < 5; i++) {
- middleArray.pop();
- }
- middleArray.push('0', '2', '3', '4');
- }