π Class
π μ μ μ κ³±κ·Ό νλ³
function solution(n){
return Number.isInteger(Math.sqrt(n))
? (Math.sqrt(n)+1) ** 2 : -1
}
solution(121)
solution(3)
== μ¬μ©λ λ©μλ ==
3 ** 2
Math.pow(3, 2)
Math.sqrt(4)
Math.sqrt(3)
Number.isInteger(4.1)
π μ μΌ μμ μ μ κ±°νκΈ°
function solution (arr){
const min = Math.min(...arr)
const answer = arr.filter(num => {
console.log(num) // 4 3 2 1 // 10
return num > min
})
return answer.length === 0 ? [-1] : answer
}
solution([4,3,2,1]) // [4,3,2]
solution([10]) // [-1]
== μ¬μ©λ λ©μλ ==
arr = [1,2,3,0]
Math.min(...arr)