7 line JavaScript solution
function minPatches(nums, n) {\n    \tfor (var sum = 0, idx = 0, added = 0; sum < n;) {\n    \t\tadded += idx === nums.length || nums[idx] > sum + 1 ? 1 : 0;\n 
    function minPatches(nums, n) {\n    \tfor (var sum = 0, idx = 0, added = 0; sum < n;) {\n    \t\tadded += idx === nums.length || nums[idx] > sum + 1 ? 1 : 0;\n    \t\tsum += (nums[idx] || n) > sum + 1 ? sum + 1 : nums[idx++];\n    \t}\n    \treturn added;\n    }
['JavaScript']