Created
August 6, 2013 16:23
-
-
Save olih/6166065 to your computer and use it in GitHub Desktop.
A few examples of simple conversions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
#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