프로그래머스를 풀면서 사용했던 내장함수들을 정리해보았다.
console.log('repeat')
const rowstar = "*".repeat(5)
console.log(rowstar)
repeat
*****
console.log('Number')
let somestr = "5500"
console.log(typeof(Number(somestr)))
Number
number
console.log('includes');
let arr = [1, 2, 3, 4, 5, "우산"];
console.log(arr.includes('우산'));
console.log(arr.includes(3));
includes
true
true
console.log('push');
let arr = [1, 2, 3, 4, 5];
arr.push('바지');
console.log(arr);
push
[ 1, 2, 3, 4, 5, '바지' ]
console.log('Number.isInteger')
console.log(Number.isInteger(3.4))
console.log(Number.isInteger(4))
Number.isInteger
false
true
console.log('sort를 사용한 내림차순, 올림차순')
let arr =[1, 4, 3, 6, 2, 4, 77, 31]
arr.sort(function compare(a, b) {
return a - b;});
console.log(arr)
arr.sort(function compare(a, b) {
return b - a;});
console.log(arr)
sort를 사용한 내림차순, 올림차순
[
1, 2, 3, 4,
4, 6, 31, 77
]
[
77, 31, 6, 4,
4, 3, 2, 1
]
console.log('isNaN')
console.log(isNaN('a'))
console.log(isNaN(44))
isNaN
true
false