It is not very helpful to check each call to see if arr is an array, if the array is empty, or if it only has one value.
"use strict";constfindMax=(arr)=>{constfmax=(arr)=>{if(arr[idx]>max)max=arr[idx]if(idx<arr.length){idx++;fmax(arr)}returnmax}if(!Array.isArray(arr))throw'Not an array'if(arr.length===0)returnundefinedif(arr.length===1)returnarr[0]letidx=0letmax=arr[idx]max=fmax(arr)returnmax}console.log(findMax([-10,-9]))console.log(findMax([1,9,100,28,78,10]))
It is not very helpful to check each call to see if arr is an array, if the array is empty, or if it only has one value.
Yeah for recursion approach it's not good
in this case for loop would be more appropriate...
Actually it is a question which is asked in an interview so i tried to solve it later because I was not able to solve it at the time of interview 😂😂
Okay, yeah, I would've refused that answer with "why on Earth would you do that?".
Yeah it won't make a difference Because they already rejected 😂😂