-
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.
-
Re: Technical puzzle
Without a for or while does that mean I should use a GoTo :)
-
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
-
Re: Technical puzzle
I was joking about the Goto but it would work.
-
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 )