목록전체 글 (119)
기술 블로그
axios와 fetch모두 데이터 패칭을 위한 도구이다. 가장 큰 차이점은 axios는 외부 라이브러이인 반면 fetch는 자바스크립트에서 기본으로 제공한다. fetch fetch('https://cataas.com/cat') .then(response => { if (!response.ok) { throw new Error('Network response was not ok'); } return response.blob(); }) .then(blob => { document.getElementById('catImage').src = URL.createObjectURL(blob); }) .catch(error => { console.error('There was a problem with the fetc..
코테중 제곱수를 확인하는 문제가 있어 아래와 같이 구현했다. parseInt(parseInt(n).toString(2).split('').reverse().join(''))===1 2의 제곱수 특성을 활용해 2진수 문자열로 변환 후 리버스 후 1과 같은지 확인했다. 다른 아래와 같은 방법도 있다. 1.비트연산 위의 이진수를 활용한 개념와 유사하지만 더 명료하게 비트연산을 활용한다. function isSquare(n) { return n > 0 && (n & (n - 1)) === 0; } 만약 n이 8이라면 8 & 7의 and연산을 수행한다. 즉 1000과 0111의 and == 0000이므로 2의 제곱수가 맞다 만약 9일경우 1001 and 1000 = 1000 != 0이므로 2의 제곱수가 아니다. ..
const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); let input = [] rl.on("line", function(line) { if(!line) { rl.close() } else { input.push(line) } }).on("close", function() { sol(input); process.exit(); }); function sol(input){ console.log(input+"hello") } https://forgottenknowledge.tistory.com/entry/%EC%95%8C%EA%B3%A0%EB..
class Heap { constructor() { this.heap = [null]; //0인덱스비워두기 } size() { return this.heap.length; } swap(i, j) { [this.heap[i], this.heap[j]] = [this.heap[j], this.heap[i]]; } heappush(value) { this.heap.push(value); let curIdx = this.heap.length - 1; // 현 노드 (위 value가 들어간 값) let parIdx = (curIdx / 2) >> 0; // 부모노드 while (curIdx > 1 && this.heap[curIdx] < this.heap[parIdx]) { //현 노드가 루트노드가 아니며, 동시..
str.indexOf(찾을 값, 시작위치) 없을경우 -1을 반환한다. str.search(정규식) str.substring(시작,끝) slice와 유사하나 음수를 사용할수없다. str.substr(시작,길이) str.replace(문자열,문자열) 발견된 첫 문자열을 바꾸어 반환한다. str.replaceAll(문자열,문자열) 모든문자열을 바꾸어 반환한다. concat(문자열,문자열) 문자열을 결합한다. 문자열.trim() 공백을 제거한다.

let a = [3, 1, 6, 2, 4, 8, 10, 5, 11, 7, 9]; a.sort(compareNumber); console.log(a); function compareNumber(i, j) { return i - j; } Math 반올림,올림,내림 Math.round(실수) Math.ceil(실수) Math.floor(실수) 거듭제곱, 제곱근 Math.pow(2,3) = 2**3 console.log(Math.sqrt(9)); console.log(Math.pow(3, 5)); console.log(Math.sqrt(9)); //243 //3 최대 최소 console.log(Math.max(1, 2, 3, 4)); console.log(Math.min(1, 2, 3, 4)); //4 //1 ..