for the problem https://leetcode.com/problems/binary-search/submissions/
my code is:
var search = function(nums, target) {
const tailRecursion = (start, nums, target) => {
let len = nums.length;
if (len == 0)
return -1;
let mid = ~~(len / 2);
if (nums[mid] == target)
return start + mid;
if (nums[mid] < target)
return tailRecursion(mid + 1, nums.slice(mid + 1, len), target);
return tailRecursion(start, nums.slice(0, mid), target);
}
return tailRecursion(0, nums, target);
};it works fine if i run the code in chrome devtool, but leetcode gives me runtime error. Please help.