With arrays, we can iteratively generate and run through every subarray within the array. Thus, the easiest brute force solution may be to simply test every subarray sum against n.
xxxxxxxxxx20
function subarraySum(nums, sum) { let currSum, i, j; for (i = 0; i < nums.length; i += 1) { currSum = nums[i]; j = i + 1; while (j <= nums.length) { if (currSum == sum) { return true; } if (currSum > sum || j == nums) { break; } currSum = currSum + nums[j]; j += 1; } } return false;}​console.log(subarraySum([1, 2, 3], 5));OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment

