String to object conversion

if you want to convert this type of string format such as

“(51.60693037835707, -99.25735473632812),(45.816357959181346, -93.19290161132812),(45.13846137581871, -121.93313598632812),(51.60693037835707, -99.25735473632812),…..”

to

{

1:{“lat”:51.60693037835707,”lan”:99.25735473632812},

2:{“lat”:45.816357959181346,”lan”:93.19290161132812},

3:{“lat”:45.13846137581871,”lan”:121.93313598632812},

.

.

.

}

then here is the simple code

var string=”(51.60693037835707, -99.25735473632812),(45.816357959181346, -93.19290161132812),(45.13846137581871, -121.93313598632812),(51.60693037835707, -99.25735473632812).”

 

var array=string.split(“,”);
var coordinates_array=[];
array.forEach(function(value,key){
var obj={};
if(key & 1){
var first=array[key].replace(‘)’,”);
coordinates_array.push(first)
}else{

var sec=array[key].replace(‘(‘,”);
coordinates_array.push(sec)

}
})
// console.log(coordinates_array);changing the string to array excluding ‘(‘ &  ‘)’
var i=-1;
var obj={};
var result={};
coordinates_array.forEach(function(value,key){
if(key %2 ==0){
i++;
result[i.toString()]={};
delete obj;
}
if(key & 1){
result[i.toString()][“lan”]=value
}else{
result[i.toString()][“lat”]=value

}

})

console.log(result)// desire result

To show on which git branch you are working currently

function parse_git_branch () {
git branch 2> /dev/null | sed -e ‘/^[^*]/d’ -e ‘s/* \(.*\)/ (\1)/’
}

RED=”\[33[0;31m\]”
YELLOW=”\[33[0;33m\]”
GREEN=”\[33[0;32m\]”
NO_COLOR=”\[33[0m\]”

PS1=”\h$NO_COLOR:\w$YELLOW\$(parse_git_branch)$NO_COLOR\$ ”

 

 

if you are Mac user paste the above code in .profile file of the current user of your system home directory

if you are Linux user the paste it in the .bashrc file of the current user of your system home directory