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

Tiller Test Dev Backend - Test #1

What should I do ?

Write a webservice that compute the sum of the numbers in a given list using a for-loop, foreach-loop, a while-loop, and recursion.

Where should I write my code ?

    //src/AppBundle/Controller/Test1Controller
    
    public function test1Action(Request $request)
    {
        $list = $request->request->get('list');

        /**
         * @TODO: 
         * Write a webservice that compute the sum of the numbers in a given 
         * list using a for-loop, foreach-loop, a while-loop, and recursion.
         */
        
        $result = array(
            'forLoop' => $this->forLoopSum($list),
            'foreachLoop' => $this->foreachLoopSum($list),
            'whileLoop' => $this->whileLoopSum($list),
            'recursion' => $this->recursionSum($list),
        );
        
        return new JsonResponse($result, JsonResponse::HTTP_OK);
    }

How can I test my code ?

$ curl -H "Content-Type: application/json" -X POST -d '{ "list":  [1, 2, 3] }' test.local/test1
{"forLoop":6,"foreachLoop":6,"whileLoop":6,"recursion":6}

Clone this wiki locally