What would be the most efficient way to convert a PostgreSQL point in the format of "(5.035,1)" to {x: 5.035, y: 1}?
The function I wrote in PHP looks like
function pointToArray($point) {
if ( strlen($point) == 0 ) return null;
$xy = explode(",", substr($point, 1, strlen($point)-2));
return array(
"x" => $xy[0],
"y" => $xy[1]
);
}
You can use the same approach in Javascript as you did in your PHP:
A naive benchmark I just did was able to execute this function 2 million times in 1.53 seconds.
And, just for good measure, here’s a regex solution shamelessly stolen from NullUserException that is marginally faster on most browsers