배열

Array.prototype.every() 함수의 이름 every()를 보면 추측을 할 수 있다.배열의 모~든 요소가 주어진 조건을 만족하는지 검사하는 것이다.- 모~두 만족하면 true 반환- 하나라도 만족하지 않는다면 false 반환 만족하지 않는 요소를 찾으면 바로 멈춘다 (뒤에 있는 요소들을 더 이상 검사하지 않는다.)  const arr = [true, true, false, true]; const result = arr.every(value => { // 여기부터 콜백 함수 console.log(value); return value; }); // 여기까지 콜백 함수// true // true // false console.log(result); // false 4번째의 true를 ..
let data = [];let a = [1, 2, 3];let b = [4, 5, 6];  a랑 b를 배열 data에 합치는 방법 concat()과 스프레드 연산자를 가장 많이 쓴다. 1. concat()let data = []; let a = [1, 2, 3]; let b = [4, 5, 6]; data = a.concat(b); console.log(data); // [1, 2, 3, 4, 5, 6]  concat()은 원본 배열을 변경하지 않고 새로운 배열을 반환한다.  2. 스프레드 연산자 (...)let data = []; let a = [1, 2, 3]; let b = [4, 5, 6]; data = [...a, ...b]; console.log(data); // [1, 2, 3, 4, 5,..
String 변수인 keyword와 label1 ~ label5가 비어있지 않다면 num++을 해주는 로직을 짰다. label1 ~ label5는 배열로 만들면 안 됐던 상황이었다. let num = 0; // keyword, label1 ~ label5 는 다른 곳에서 받아오는 값 if(keyword !== "" && keyword !== null){ num++; } if((label1 !== "" && label1 !== null)){ num++; } if((label2 !== "" && label2 !== null)){ num++; } if((label3 !== "" && label3 !== null)){ num++; } if((label4 !== "" && label4 !== null)){ num..
문제 https://www.acmicpc.net/problem/16935 16935번: 배열 돌리기 3 크기가 N×M인 배열이 있을 때, 배열에 연산을 R번 적용하려고 한다. 연산은 총 6가지가 있다. 1번 연산은 배열을 상하 반전시키는 연산이다. 1 6 2 9 8 4 → 4 2 9 3 1 8 7 2 6 9 8 2 → 9 2 3 6 1 5 1 8 3 4 2 9 → www.acmicpc.net 풀이 배열 돌리다가 내 머리가 돌아갈뻔,,했다 import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStream..
해버니
'배열' 태그의 글 목록