daily pastebin goal
31%
SHARE
TWEET

Untitled

a guest Jan 12th, 2018 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Simplify version
  2.  
  3. // Itterative
  4. function max1(list){
  5.   var result = -Infinity;
  6.   for (var i = 0; i < list.length; i++) {
  7.     result <= list[i] && (result = list[i]);
  8.   }
  9.   return result;
  10. }
  11.  
  12. document.write(max1([-1,-2,-3,1,2,3]))
  13.  
  14. // Recursive
  15. function max(list, max_value) {
  16.   max_value = max_value || -Infinity;
  17.   if (list.length != 0) {
  18.     return max(list.slice(1), (list[0] > max_value ? list[0] : max_value));
  19.   } else {
  20.     return max_value;
  21.   }
  22. }
  23.  
  24. document.write(max([-1,-2,-3,1,2,3]))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top