백준 풀이용 메소드 정리 (node.js)

vhv3y8·2022년 8월 7일
0

node.js

입력 받기

const input = require("fs").readFileSync("/dev/stdin").toString().trim().split("\n");

출력

console.log("Hello World");

문자를 숫자로 바꾸기

const N = +input[0];
// 또는
const N = parseInt(input[0]);

공백을 두고 주어진 숫자들 받기

let array = input[1].split(" ").map(str => +str);

0으로 10개 채워진 배열 만들기

let filled = new Array(10).fill(0);

내림차순 정렬하기

let sorted = array.sort((a, b) => b - a);

숫자 크기

BigInt

정의

const alsoHuge = BigInt(9007199254740991)
// ↪ 9007199254740991n
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt

계산

let num = alsoHuge + anotherBigInt;

BigInt끼리 자유롭게 가능하다

출력

console.log(alsoHuge.toString());

마지막 n을 없애준다

Array 메소드들

  • Array.push(value)
  • Array.pop()
  • Array.reverse()
  • Array.shift()
  • Array.unshift()
  • Array.slice(index) : slice(1) = index 1부터 끝까지를 반환
  • Array.splice() : 값을 바꾼다 (시작, 지울 개수, 바꿀 값)
  • Array.forEach(function)
  • Array.map(function)
  • Array.reduce(function)
  • Array.entries()
  • Array.sort(function)
  • Array.filter(function)
  • Array.every()
  • Array.some()
  • Array.includes(value)
  • Array.fill(value)
  • Array.indexOf(value)
  • Array.join(string)
    ...

문자열 메소드들

  • String.charAt(index)
  • String.charCodeAt(index) : UTF-16 코드. A = 65, a = 97
  • String.includes()
  • String.repeat(times)
  • String.match(regex)
  • String.replace() : (regex, 바꿀 값) 또는 (substring, 바꿀 값)
  • String.split(string)
    ...

Math 메소드들

  • Math.pow(x, y) : x^y
  • Math.abs() : 절댓값
  • Math.ceil()
  • Math.floor()
  • Math.round()
  • Math.exp()
  • Math.min()
  • Math.max()
  • Math.sqrt()
    ...

profile
미래의 나에게 설명하기

0개의 댓글