Skip to content
Vincent Oliveira edited this page Sep 6, 2016 · 3 revisions

Tiller Test Dev Backend - Test #2

What should I do ?

Write a webservice that combines two lists by alternatingly taking elements. For exemple: given two lists [A, B, C] and [1, 2, 3], the results sould be [A, 1, B, 2, C, 3]

Where should I write my code ?

    //src/AppBundle/Controller/Test2Controller
    
    public function test2Action(Request $request)
    {
        $list1 = $request->request->get('list1');
        $list2 = $request->request->get('list2');
        
        $finalList = array();

        /**
         * @TODO: 
         * Write a webservice that combines two lists by alternatingly taking 
         * elements. For exemple: given two lists [A, B, C] and [1, 2, 3], the 
         * results sould be [A, 1, B, 2, C, 3]
         */
        
        return new JsonResponse($finalList, JsonResponse::HTTP_OK);
    }

How can I test my code ?

$ curl -H "Content-Type: application/json" -X POST -d '{ "list1": ["a", "b", "c"], "list2": [1, 2, 3] }' test.local/test2
["a",1,"b",2,"c",3]

Clone this wiki locally