function timeFunc(func) { var start = new Date().getTime() console.log('开始') func() var end = new Date().getTime() console.log('结束') console.log(end - start + ' ms'); } function twoSum(nums = [3, 3, 4], target = 6) { const resArr = [] for (let index = 0; index < nums.length; index++) { let oth = nums.slice(index+1) if (oth.length === 0) break if(oth.indexOf(target - nums[index]) !== -1){ resArr.push(index,oth.indexOf(target - nums[index]+index)) } console.log(resArr) } } timeFunc(twoSum)