Last active
August 29, 2015 14:05
-
-
Save culttm/20b9aa8d8136925157f7 to your computer and use it in GitHub Desktop.
Возвращает максимальное значение массива без помощи встроенной функции
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var numbers = [100, 200, 150, 50, 250]; | |
var max = function(array){ | |
var arrayLen = array.length; | |
var number; | |
if (arrayLen){ | |
number = array[0]; | |
for (var x = 0; x < arrayLen; x+=1){ | |
if (number < array[x]){ | |
number = array[x]; | |
} | |
} | |
} | |
return number; | |
}; | |
max(numbers); // 250 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment