νμ 곡λΆ/𫧠μκ³ λ¦¬μ¦ κ³΅λΆ
[λ°±μ€/Node.js] 10818λ² νμ΄ || JavaScript
λμπ
2023. 3. 4. 10:57
728x90
let input = require('fs').readFileSync('/dev/stdin').toString().trim().split("\n");
let testArray = input[1].split(" ").map(i => Number(i));
console.log(Math.min(...testArray), Math.max(...testArray));
π μ΅λκ°κ³Ό μ΅μκ°μ ꡬνλ λ°©λ²κ³Ό λ°°μ΄μμ κ°λ§ κΊΌλ΄λ λ°©λ²μ μλ©΄ λ무 κ°λ¨νκ² κ΅¬νμ΄ κ°λ₯νλ€.
π μ΅λκ° κ΅¬νκΈ° : Math.max(1, 2, 3, 4)
π μ΅μκ° κ΅¬νκΈ° : Math.min(5, 2, 5, 7)
=> λλ€ νλΌλ―Έν°λ‘ μ λ ₯λ°μ κ°λ€ μ΅λκ°κ³Ό μ΅μκ°μ ꡬν΄μ 리ν΄νλ ν¨μλ€μ΄λ€.
+ λ°°μ΄μ κ·Έλλ‘ λ겨주λ λ°©λ²λ μλ€.
console.log(Math.min.apply(null, testArray), Math.max.apply(null, testArray));
πMath.max.apply(null, λ°°μ΄)
null μλ μλ Math.max() ν¨μ λ΄λΆμμ μ¬μ©ν this κ°μ²΄λ₯Ό μ λ¬ν΄μΌνμ§λ§,
μ£Όμ΄μ§ λ°°μ΄λ§ κ°μ§κ³ λ²μλ₯Ό ꡬνκΈ° λλ¬Έμ null μ μ λ¬ν΄μ€λ€.
728x90
λ°μν