|
-
Feb 20th, 2012, 08:57 AM
#1
Thread Starter
Lively Member
Technical puzzle
Your application has a object named Company, which has properties as Name, Address & Code. Also, you have an object named Companies containing list (array) of Company. Can you write a code to print out all the properties of all the Company object in the Companies object, separated by *#* string as shown below.
Company1Name*#*Company1Address*#*Company1Code*#* Company2Name*#*Company2Address*#*Company2Code….. *#* Company100Name*#*Company100Address*#*Company100Code
Think of a solution without any loop (for or while) and leverage your language’s feature.
-
Feb 20th, 2012, 07:40 PM
#2
Re: Technical puzzle
Without a for or while does that mean I should use a GoTo
-
Feb 20th, 2012, 09:57 PM
#3
Re: Technical puzzle
which language is this in?
That said, it's a jacked exercise, contrived with no real-world application what so ever (especially if the answer is using a goto, which I don't think it is)...
-tg
-
Feb 20th, 2012, 10:46 PM
#4
Re: Technical puzzle
I was joking about the Goto but it would work.
-
Feb 22nd, 2012, 09:54 AM
#5
Re: Technical puzzle
using F# I would use List.Iter and a simple lambda.
Code:
type company = {name : string; adress : string; code : int}
let companies = [{name = "abc";adress = "123";code = 1};{name = "dfg";adress = "456";code = 2}]
companies |> List.iter (fun x -> printfn "%s*#*%s*#*%d" x.name x.adress x.code )
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|