---
title: "Discussion on \"Code I did for Codewars...\" | Hashnode"
description: "Discussion on \"Code I did for Codewars...\". One of the problems I did on Codewars today was to add the two smallest numbers in an array. The array was [19, 5, 42, 2, 77]. It has been literally months since I did this so my mind was confused. Instead of googling and typing the answer down, I wa..."
url: "https://hashnode.com/posts/code-i-did-for-codewars/616eb6bc41c1b75f924d907a"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Code I did for Codewars...](https://joemcgee4151986.hashnode.dev/code-i-did-for-codewars?utm_source=hashnode&utm_medium=feed)

One of the problems I did on Codewars today was to add the two smallest numbers in an array. The array was \[19, 5, 42, 2, 77\]. It has been literally months since I did this so my mind was confused. Instead of googling and typing the answer down, I wa...

Oct 19, 2021 · 1 min read · joemcgee4151986.hashnode.dev  
Read the article

-   [#codenewbies](https://hashnode.com/tag/codenewbies)
-   [#javascript](https://hashnode.com/tag/javascript)

## Written by

[Joe McGee](https://hashnode.com/@joemcgee4151986)

@joemcgee4151986 · Gwangju, South Korea

  
[View profile](https://hashnode.com/@joemcgee4151986)

Software engineer student @ 100 Devs

While I am not programming, I like to play video games, exercise, take care of my family.

## Responses 1

Markdown supported · ⌘↵ to post

[Tobbe Lundberg](https://hashnode.com/@tobbe)

[Oct 19, 2021](https://hashnode.com/posts/code-i-did-for-codewars/616eb6bc41c1b75f924d907a/comment/616f1da7f1f4c944cc6b56f1)

I saw this, and had to try it myself

Here's another way to do it. Probably worse than your solution. But I wanted to make it a chain of function calls

```
function sumTwoSmallestNumbers(numbers) {
  return (numbers.sort((a, b) => a - b))
    .slice(0, 2)
    .reduce((prev, cur) => prev + cur)
}
```

[Joe McGee](https://hashnode.com/@joemcgee4151986)

[Oct 20, 2021](https://hashnode.com/posts/code-i-did-for-codewars/616eb6bc41c1b75f924d907a/comment/616f1da7f1f4c944cc6b56f1#reply-617007d3d78c655a23127fc7)

interesting use of the .slice method. I would have never thought of that.
