JS - forEach(), reduce()
forEach()const a = [1,2,3,4,5];라는 배열이 있다고 하자.forEach()를 통해 각 배열의 원소들을 순회할 수 있다.a.forEach((n, idx, arr) => { console.log(n, idx, arr);})1 0 [ 1, 2, 3, 4, 5 ]2 1 [ 1, 2, 3, 4, 5 ]3 2 [ 1, 2, 3, 4, 5 ]4 3 [ 1, 2, 3, 4, 5 ]5 4 [ 1, 2, 3, 4, 5 ]forEach문의첫번째 인자 n : 각 배열의 원소들두번째 인자 idx : 원소들의 인덱스세번째 인자 arr : 순회하는 배열reduce()const a = [1,2,3,4,5];라는 배열이 있다고 하자.reduce()는 배열의 요소를 순차적으로 순회하며 숫자든 배열이든 객체든..
2024. 7. 5.
[백준][js] 20436_ZOAC 3
문제https://www.acmicpc.net/problem/20436 결과풀이const fs = require("fs");const filePath = process.platform === "linux" ? "/dev/stdin" : "boj/input.txt";const input = fs.readFileSync(filePath).toString().trim().split("\n");key = [['q','w','e','r','t','y','u','i','o','p'], ['a','s','d','f','g','h','j','k','l'], ['z','x','c','v','b','n','m']];right = ['y','u','i','o','p','h','j','k','l','..
2024. 6. 23.