function subarraySum(nums, k) {
  // end::description[]
  // tag::placeholder[]
  // write your code here...
  // end::placeholder[]
  // tag::solution[]
  let ans = 0;
  let sum = 0;
  const map = new Map([[0, 1]]);

  for (let i = 0; i < nums.length; i++) {
    sum += nums[i];
    if (map.has(sum - k)) ans += map.get(sum - k);
    map.set(sum, 1 + (map.get(sum) || 0));
  }

  return ans;
  // end::solution[]
  // tag::description[]
}
Find the number of subarrays that add up to k.
@example subarraySum([1, -1, 1], 0); // 3 ([1,-1,1], [1], [1])
@param {number[]} nums - Array of integers.
@param {number} k - The target sum.
@returns {number} - The number of solutions.