Skip to content

Commit

Permalink
Create Smallest Pair Sum.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Automedon authored Aug 2, 2019
1 parent 0a48f57 commit 68ddc46
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Smallest Pair Sum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
Description:
Given an array of numbers, find the smallest pair sum in the array.
For example
[10,14,2,23,19] should return 12 (i.e. sum of 10,2)
[99,2,2,23,19] should return 4 (i.e. sum of 2,2)
Input array contains minimum two elements and every element is a number. Note :
not all elements are distinct, and duplicates are not ignored
Ex :
[1,1,2] => 1+1 = 2
*/
function smallestPairSum(numbers)
{
numbers=numbers.sort((a,b)=>a-b)
return numbers[0]+numbers[1]
}

0 comments on commit 68ddc46

Please sign in to comment.