# # 1085 Sum of Digits in the Minimum Number.

[LeetCode](https://leetcode.com/problems/sum-of-digits-in-the-minimum-number/)

```
Given an array A of positive integers, 
let S be the sum of the digits of the minimal element of A.

Return 0 if S is odd, otherwise return 1.

input: 一串正整數字陣列
output: 找出這個數字相加是奇數就回傳 0，不然就回傳 1
```

```
Example 1:

Input: [34,23,1,24,75,33,54,8]
Output: 0
Explanation: 
The minimal element is 1, and the sum of those digits is S = 1 
which is odd, so the answer is 0.


Example 2:

Input: [99,77,33,66,55]
Output: 1
Explanation: 
The minimal element is 33, and the sum of those digits is S = 3 + 3 = 6 which is even, so the answer is 1.
 

Note:

1 <= A.length <= 100
1 <= A[i].length <= 100

/**
 * @param {number[]} A
 * @return {number}
 */

var sumOfDigits = function(A) {}
```

### 怎麼解

&#x20;先用 reduce Math.min 找出最小的然後自己相加

```
var sumOfDigits = function(A) {
    let myMin = A.reduce((acc, cur) => {
        return Math.min(acc, cur)
    })
    // 這邊也不一定要轉成字串，可以用數字方法解決
    let result = 0, stringMin = myMin.toString();
    for(let i = 0; i< stringMin.length; i++){
        // console.log(result)
        result += Number(stringMin[i])
    }
    return result%2 == 0 ? 1 : 0;
};

console.log(sumOfDigits([99,77,33,66,55]))

// Runtime: 36 ms, faster than 100.00% of JavaScript online submissions 
```

```javascript
function addDigits(num){
  let sum = 0
  while(num/10 > 0){
    sum += num%10
    num = Math.floor(num/10)
  }
  
  return sum
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hannahpun.gitbook.io/leetcode-note/math/1085-sum-of-digits-in-the-minimum-number..md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
