Preview:
function subarraySum(nums, k) {
    let dict = {0:1};
    let counter = 0;
    let summ = 0;
    for(let i = 0; i < nums.length; i++) {
        summ += nums[i];
        if (dict[summ - k])
            counter += dict[summ - k];
        if (dict[summ])
            dict[summ]++;
        else
            dict[summ] = 1;
    }
    return counter;
};
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter