Question: We are using the chart.js library. The framework used is Slim from Rails. I'm using JavaScript.　　

I get an Error:

> 
> Uncaught SyntaxError: Unexpected token 'if' error in the
> if(user.activity\_type === "groupA").
> 
> 
> 

```
 script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.min.js"
  javascript:
    var users = #{raw @user.to_json}
    let count = 0;
    let month = "";
    let array = [];
    var ct = document.getElementById('ex_chart');
    var ex_chart = new Chart(ct, {
        type: 'horizontalBar',
        data: {
        labels: ["Jan", "Feb", "Mar", "Apr"],
          datasets: [
            {
              data: users.map((user) => (
                    if(user.activity_type === "groupA") {
                        if(month === "" || month === user.month) {
                          count += user.count;
                        } else {
                          array.push(count);
                          count = user.count;
                          month = user.month;
                        }
                      return array;
                    }
              ),
              backgroundColor: '#ff7f50'
            }},
            {
              data: [880, 740, 900, 520, 930],
              backgroundColor: '#ff6347'
            }
          ]
          });
        },
        options: options
    })

    var options = {
        scales: {
            xAxes: [{
                ticks: {
                    min: 300
                }
            }]
        }
    };

```

Answer: 
I got it working now, i initialized a new pointer that points to the predecessor, just before the `h= h->next;` statement, so for example `predecessor = h;`
What type of variables have you created in `node`? If it has a `key` in ascending order to keep track of your nodes, then you can get the key of predecessor by subtracting one from `key of node with minimum value`.
Or you could create a double linked link list which points to previous element as well by making a pointer named `previous` in `node` type.