diff --git a/solution/1900-1999/1913.Maximum Product Difference Between Two Pairs/README.md b/solution/1900-1999/1913.Maximum Product Difference Between Two Pairs/README.md index b3943e945949a..3d0b2e8ea0acb 100644 --- a/solution/1900-1999/1913.Maximum Product Difference Between Two Pairs/README.md +++ b/solution/1900-1999/1913.Maximum Product Difference Between Two Pairs/README.md @@ -66,6 +66,21 @@ ``` +### **JavaScript** + +```js +/** + * @param {number[]} nums + * @return {number} + */ +var maxProductDifference = function(nums) { + nums.sort((a, b) => a - b); + let n = nums.length; + let ans = nums[n - 1] * nums[n - 2] - nums[0] * nums[1]; + return ans; +}; +``` + ### **...** ``` diff --git a/solution/1900-1999/1913.Maximum Product Difference Between Two Pairs/README_EN.md b/solution/1900-1999/1913.Maximum Product Difference Between Two Pairs/README_EN.md index e7dac423a66f9..6df8e7e78a107 100644 --- a/solution/1900-1999/1913.Maximum Product Difference Between Two Pairs/README_EN.md +++ b/solution/1900-1999/1913.Maximum Product Difference Between Two Pairs/README_EN.md @@ -87,6 +87,21 @@ The product difference is (9 * 8) - (2 * 4) = 64. ``` +### **JavaScript** + +```js +/** + * @param {number[]} nums + * @return {number} + */ +var maxProductDifference = function(nums) { + nums.sort((a, b) => a - b); + let n = nums.length; + let ans = nums[n - 1] * nums[n - 2] - nums[0] * nums[1]; + return ans; +}; +``` + ### **...** ``` diff --git a/solution/1900-1999/1913.Maximum Product Difference Between Two Pairs/Solution.js b/solution/1900-1999/1913.Maximum Product Difference Between Two Pairs/Solution.js new file mode 100644 index 0000000000000..56b164fb5876d --- /dev/null +++ b/solution/1900-1999/1913.Maximum Product Difference Between Two Pairs/Solution.js @@ -0,0 +1,10 @@ +/** + * @param {number[]} nums + * @return {number} + */ + var maxProductDifference = function(nums) { + nums.sort((a, b) => a - b); + let n = nums.length; + let ans = nums[n - 1] * nums[n - 2] - nums[0] * nums[1]; + return ans; +}; \ No newline at end of file