[WITHOUT USING MIN / MATH Function]
Ask a question to create a function that includes 2 parameters. The first is an array, and the second parameter is the string " Minimum " or " Maximum ". This confuses me when I don't know how to enter a parameter as a string in a function. So I decided to create 2 similar functions, such as extremeValue(vector, maximum) and extremeValue(vector, minimum) (I still don't know if I can do this or not). And this is my code for extremeValue(vector, maximum) .
So, the way I did this is to create an array that has the same meaning with vector[i] that I use the if statement to see if it is larger than this vector or not. However, the code does not work. :(
var vector = [3, 1, 1] var maximum //------------this function give us the vector with all same value---------------// function set(value, len) { var arr = []; for (var i = 0; i < len; i++) { arr.push(value); } return arr; } //---------------------------------------------------// //---------------------------------------------------// function extremeValue(vector, maximum) { var answer = ""; for (var count = 1; count++; count < vector.length) { if (set(vector[count], vector.length) > vector) answer += vector[count] + "is maximum" } return answer } //---------------------------------------------------// console.log(extremeValue(vector, maximum))
source share