Skip to content

Instantly share code, notes, and snippets.

@olih
Created August 6, 2013 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olih/6166065 to your computer and use it in GitHub Desktop.
Save olih/6166065 to your computer and use it in GitHub Desktop.
A few examples of simple conversions
#
#Creator: 2013, Olivier Huin (https://github.com/olih)
#License: Eclipse Public License - v 1.0
#Contributors:
#
pairToMap= (key,value)->
row=
Name: key
Value: value
return row
mapToPair= (row, obj)->
key=row["Name"]
value=row["Value"]
obj[key]=value
return row
objToSequence= (data)->
return null if not data
r=[]
for key,value of data
r.push pairToMap(key,value)
return r
sequenceToObj= (data)->
return null if not data
r={}
for row in data
mapToPair(row,r)
return r
stuff=
a: "alpha"
b: "bravo"
c: "charlie"
seq=[ { Name: 'a', Value: 'alpha' },
{ Name: 'b', Value: 'bravo' },
{ Name: 'c', Value: 'charlie' } ]
console.log objToSequence(stuff)
console.log sequenceToObj(seq)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment