PROBLEM 53
Medium

Smallest Digit

Programming Basics · JavaScript

</>
STATUS Not solved

TASK

Problem

#53

Given a positive three-digit integer, print its smallest digit without using `Math.min()`.

EXAMPLE

Example

Input
583
Output
3

LIMITS

Constraints

100 ≤ n ≤ 999
📖
LEARN Theory for this problem
+

### Smallest Digit

Integer division separates higher decimal/time units, while `%` returns the remainder. These two operations let a program isolate digits or split a total number of seconds/minutes into components.

💡
NEED HELP? Hints
+

['Decide which part comes from division and which part comes from the remainder.', 'Mentally substitute at least one value for each branch and verify that exactly the intended branch runs.']

ANSWER Solution
+
const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trimEnd();
let n = Number(input);
let a = Math.floor((n) / (100));
let b = (((Math.floor((n) / (10))) % (10)) + (10)) % (10);
let c = (((n) % (10)) + (10)) % (10);
let m = a;
if (b < m) {
    m = b;
}
if (c < m) {
    m = c;
}
console.log(m);