JavaScript solution using array methods, for loop and prefix sum.
Intuition:\nSimple array map method followed by array sort then finding the summation using for loop and prefix sum. For summation, two nested for loops only ca
# Intuition:\nSimple array map method followed by array sort then finding the summation using for loop and prefix sum. For summation, two nested for loops only can be used but that will give time out error here in this website.\n\n# Approach:\nJust ignore the collisions as all the robots are identical. Only consider left or right movements without any stop for the given seconds.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n/**\n * @param {number[]} nums\n * @param {string} s\n * @param {number} d\n * @return {number}\n */\nvar sumDistance = function (nums, s, d) {\n    let sum = 0;\n    nums = nums.map((val, i) => {\n        if (s[i] === "L") {\n            return val - d;\n        } else {\n            return val + d;\n        }\n    })\n    nums.sort((a, b) => (a - b));\n    let arr = nums.slice();\n    for (let x = 1; x < nums.length; x++) {\n        sum = (sum + x * nums[x] - arr[x - 1])%1000000007;\n        arr[x] = (nums[x] + arr[x - 1])%1000000007;\n    }\n    return sum;\n};\n```
['JavaScript']