Question: Inspired by `arr2D[i][j]` and `arr1D[i * k + j]` after reading [this post](https://stackoverflow.com/q/59970668/10251345) and the comments under it, I would like to know an algorithm that can change the dimensions of any array.

*Let me try to formalize it:*

**Input:**

1. An `M`-dimensional container `A`
2. The dimensions `D` of the container (size)
3. Target dimension `N`

**Output:**

If `N > 0` then return an N-dimensional container `B` with the same contents as `A` in order otherwise return an error code.

**Note:**

You may choose any optimal size for the N-dimensional container.

**Edit:**

I don't need any fully working code. I'm asking if there's any algorithm that does this?

Answer: 
If you are looking to do an interval, you should not use `setTimeout`, but rather `setInterval`. 

The `setInterval` function works in the same way as the `setTimeout`, it takes a callback and an amount of milliseconds. It also return an interval object that can be used to stop the interval when passing it to the `clearInterval` function.

Your code was not working because you were never changing the value of `weightingall`. So you would end up with the same amount each time.

Here I've produce a working prototype of your code. Please note that i've removed a few things in order to make it work properly. You can't simply copy and paste this into your code expecting every thing to works.

```js
var weightingall = 100;
let interval = setInterval(() => {
  var weighting1 = 10;
  // we remove 10 each time.
  weightingall = weightingall - weighting1;
  document.getElementById("display").innerHTML = weightingall;
  // if the weightingall variable comes down to 0, we clear the interval.
  if(weightingall <= 0 ){
    clearInterval(interval);
  }
}, 1000);
```

```html
<div id="display"></div>
```

Please note that i've used Arrow function and `let` here for scoping issue.  
 [You should always use `let`/`const` rather than `var`](https://stackoverflow.com/questions/762011/whats-the-difference-between-using-let-and-var)
This might help?

```js
let counter = 100;

function countdown() {
    console.log(counter--)        
    if(counter >= 0) { setTimeout(countdown, 50) }
}
countdown()
```