Readable Javascript Solution
Javscript solution of https://leetcode.com/problems/swap-adjacent-in-lr-string/discuss/113789/Simple-Java-one-pass-O(n)-solution-with-explaination\n\nIdea is to
Javscript solution of https://leetcode.com/problems/swap-adjacent-in-lr-string/discuss/113789/Simple-Java-one-pass-O(n)-solution-with-explaination\n\nIdea is to get non-X chars and compare their positions\n\n```\nfunction canTransform(start, end) {\n  start = start.replace(/X/g, \'\');\n  end = end.replace(/X/g, \'\');\n\n  if (start !== end) return false;\n\n  let p1 = 0;\n  let p2 = 0;\n\n  while (p1 < start.length && p2 < end.length) {\n    // find non-X char\n    while (p1 < start.length && start[p1] === \'X\') p1++;\n    while (p2 < end.length && end[p2] === \'X\') p2++;\n\n    // if both reached the end then they are the same\n    if (p1 === start.length && p2 === end.length) return true;\n\n    // if only one reached the end then they are not transformable\n    if (p1 === start.length || p2 === end.length) return false;\n\n    if (start[p1] !== end[p2]) return false;\n\n    if (start[p1] === \'L\' && p2 > p1) return false;\n\n    if (start[p1] === \'R\' && p1 > p2) return false;\n\n    p1++;\n    p2++;\n  }\n\n  return true;\n}\n```
[]