Skip to content

Latest commit

 

History

History
26 lines (19 loc) · 773 Bytes

sum-of-two-lowest-positive-integers.md

File metadata and controls

26 lines (19 loc) · 773 Bytes

Sum of two lowest positive integers 7 Kyu

LINK TO THE KATA - ARRAYS FUNDAMENTALS

Description

Create a function that returns the sum of the two lowest positive numbers given an array of minimum 4 positive integers. No floats or non-positive integers will be passed.

For example, when an array is passed like [19, 5, 42, 2, 77], the output should be 7.

[10, 343445353, 3453445, 3453545353453] should return 3453455.

Solution

const sumTwoSmallestNumbers = numbers => {
  return numbers
    .sort((a, b) => a - b)
    .slice(0, 2)
    .reduce((acc, curr) => acc + curr)
}