We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
functionquartiles($arr){// Write your code heresort($arr);$length=count($arr);$q1=median(array_slice($arr,0,floor($length/2)));$q2=$length%2===0?median($arr):median($arr[floor($length/2)]);$q3=median(array_slice($arr,-floor($length/2)));return[$q1,$q2,$q3];}functionmedian($nums){if(is_numeric($nums)){return$nums;}$length=count($nums);return$length%2===0?($nums[(floor($length/2)-1)]+$nums[(floor($length/2))])/2:$nums[floor($length/2)];}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day 1: Quartiles
You are viewing a single comment's thread. Return to all comments →
With PHP: