Jump to content




Need Help Converting Arrays


  • You cannot reply to this topic
4 replies to this topic

#1 Shazz

  • Members
  • 175 posts

Posted 17 June 2013 - 09:02 PM

Okay, so I'm working on this project and I need people to translate this array into their favourite programming languages.
You need to put it in a readable format and exactly how you would write it if you were to declare it (so it actually compiles/executes).
Please no esoteric programming languages.
Thank you very much!

Here is the array in JSON format (if you don't understand/know JSON then check the spoiler):
{
   "strVal":"Hello world!",
   "intVal":42,
   "floatVal":3.14,
   "boolVal":false,
   "nullVal":null,
   "0":"randomValue",
   "arrayCeption":[
	  "Hello world!",
	  42,
	  3.14,
	  false,
	  null
   ]
}

What I have so far:
Spoiler


#2 Engineer

  • Members
  • 1,378 posts
  • LocationThe Netherlands

Posted 18 June 2013 - 01:48 AM

Java :)
import java.util.HashMap;

public class Main {
	public static void main(String[] args){
		HashMap<String, Object> table = new HashMap<String, Object>();
		table.put("strVal", "Hello world!");
		table.put("intVal", 42);
		table.put("floatVal", 3.14);
		table.put("boolVal", false);
		table.put("nullVal", null);
		table.put("0", "randomValue");
		table.put("arrayCeption", new Object[] {"Hello world!", 42, 3.14, false, null} );
	}
}


#3 GravityScore

  • Members
  • 796 posts
  • LocationLand of Meh

Posted 18 June 2013 - 07:08 AM

Objective C:
NSDictionary *arr = [NSDictionary dictionaryWithObjectsAndKeys:
  "Hello world!", "strVal",
  [NSNumber numberWithInt: 42], "intVal",
  [NSNumber numberWithFloat: 3.14], "floatVal",
  // Can't be bothered doing the rest, you get the point :P/>
  [NSArray arrayWithObjects: "hello world", [NSNumber numberWithInt: 42], [NSNumber numberWithFloat: 3.14], nil], "arrayCeption",
  nil];


#4 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 18 June 2013 - 03:41 PM

Python dictionary:
arr = dict(
  strVal = 'Hello world!',
  intVal = 42,
  floatVal = 3.14,
  boolVal = False,
  nullVal = None,
  '0' = 'randomValue',
  arrayCeption = ['Hello world!', 42, 3.14, False, None]
)

Ruby dictionary:
arr = {
  'strVal': 'Hello world!',
  'intVal': 42,
  'floatVal': 3.14,
  'boolVal': false,
  'nullVal': nil,
  '0': 'randomValue',
  'arrayCeption': ['Hello world!', 42, 3.14, false, nil]
}

The ruby dictionary is basically the python dictionary, except "false" is "False" and "nil" is "None". The "dict()" syntax is just cleaner in my opinion.

#5 Shazz

  • Members
  • 175 posts

Posted 18 June 2013 - 03:56 PM

Added them all, except Objective C - it's incomplete. I would try to complete it but that I don't know any Obj-C, it looks like complete gibberish to me. Thanks for contributing.





3 user(s) are reading this topic

0 members, 3 guests, 0 anonymous users