Gravitational Force Between Numbers The gravitational force is a force that attracts any two objects with mass. In this challenge our objects will be Numbers and their mass will be their value. To do so, we don't care about the strength of the force but the direction of it.

Imagine this set of numbers 

[1 6 9 4 6 9 7 6 4 4 9 8 7]


Each of them creates a force between itself and it's adjacent numbers. Under some conditions, this will cause another number to be attracted (moved) toward a number. When the number is bigger than the adjacent, it attracts it. Lets take a look at our previous example:

[1 → 6 → 9 ← 4 6 → 9 ← 7 ← 6 ← 4 4 → 9 ← 8 ← 7]


The number 1 is not big enough to move 6, but the number 6 is, etc... Basically, numbers are moved to the biggest adjacent number (also bigger than the number itself). If both of the adjacent numbers are equal it is not attracted then. It also happens when the number and it adjacent are equal.

This is only to show the attraction, but what happens after? Numbers that collide due to attraction are summed up:

[20 32 28]


So basically the challenge is, Given a set of numbers, output the result of the attracted set of numbers.



Example 1

Input  =&gt; [10 15 20 10 20 10 10]
          [10 → 15 → 20 10 20 ← 10 10]
Output =&gt; [45 10 30 10]


Example 2

Input  =&gt; [9 9 9 9 8 1 8]
          [9 9 9 9 ← 8 1 8]
Output =&gt; [9 9 9 17 1 8]


Example 3

Input  =&gt; [1 6 9 4 6 9 7 6 4 4 9 8 7]
          [1 → 6 → 9 ← 4 6 → 9 ← 7 ← 6 ← 4 4 → 9 ← 8 ← 7]
Output =&gt; [20 32 28]


Example 4

Input  =&gt; [1 2 3 2 1]
          [1 → 2 → 3 ← 2 ← 1]
Output =&gt; [9]


Example 5

Input  =&gt; [1]
Output =&gt; [1]


Example 6

Input  =&gt; [1 1]
Output =&gt; [1 1]


Example 7

Input  =&gt; [2 1 4]
Output =&gt; [2 5]




Notes


Attraction only happens once
Numbers are not attracted to non-adjacent Numbers
The set of numbers will only contain positive integers
JavaScript (ES6),  106 104  100 bytes
Saved 2 bytes thanks to @Shaggy

a=&gt;a.filter(n=&gt;n,[...a].map((v,i)=&gt;a[a[p&gt;v&amp;(n=~~a[i+1])&lt;p?k:i+(k=i,n&gt;v&amp;p&lt;n)]+=x=a[i],p=v,i]-=x,p=0))

Try it online!
Commented
We first update the original input array a[] by iterating on a copy of it. During this step, all values 'attracted' by other ones are set to \$0\$.
Because the array is parsed from left to right, we can just add \$a_i\$ to \$a_{i+1}\$ whenever a value is attracted by its right neighbor.
Example: \$4\rightarrow5\rightarrow6\$ is turned into \$[0,\color{red}9,6]\$ and then \$[0,0,\color{red}{15}]\$.
But when several values in a row are attracted by their left neighbor, we need to add \$a_i\$ to the first attractor \$a_k\$ of this sequence (with \$k&lt;i\$) rather than simply \$a_{i-1}\$.
Example: \$6\leftarrow5\leftarrow4\$ is turned into \$[\color{red}{11},0,4]\$ and then \$[\color{red}{15},0,0]\$.
[...a]                 // create a copy of a[]
.map((v, i) =&gt;         // for each value v in a[] at position i:
  a[                   //   this statement updates a[i]:
    a[                 //     this statement updates either a[i] or an adjacent value:
      p &gt; v &amp;          //       if the previous value p is greater than v
      (n = ~~a[i + 1]) //       and the next value n
      &lt; p ?            //       is less than p (attraction to the left):
        k              //         use k (k is initially undefined, but this code cannot
                       //         be triggered during the first iteration)
      :                //       else:
        i + (          //         use either i or i + 1:
          k = i,       //           set k to i
          n &gt; v &amp;      //           use i + 1 if n is greater than v
          p &lt; n        //           and p is less than n (attraction to the right)
        )              //
    ] += x = a[i],     //     add x = a[i] to the entry defined above
    p = v,             //     update the previous value to v
    i                  //     actual index to update a[i]
  ] -= x,              //   subtract x from a[i]
  p = 0                //   start with p = 0
)                      // end of map()

We then filter out all entries equal to \$0\$.
a.filter(n =&gt; n)