Hi , I am currently working on this problem but could not be able to get the output. How caniI use an array of integers of my desired numbers?
Here is my code. I tried
console.log( maxproduct([1,2,3])); but no luck yet.
PLEASE HELP !!!
function max(arr) {
// write your code here
let product = 0;
for (let i=0; i<arr.length; i++){
for(let j= i+1; j<arr.length; j++){
let maxProduct= arr[i] * arr[j];
if (maxProduct > product){
maxProduct = product
}
}
}
return maxProduct;
};
I think you have some confusion going on with variables.
It seems that you are using product to store result.
However, you are returning maxProduct
And there are some assigning in the loop which doesn’t make much sense:
Do you really want to assign product value to maxProduct here?
And one more little thingy(maybe a spoiler): do you really need to get every possible product here? You can just find two biggest numbers in this array, and get their product.