[JS] 프로그래머스 Lv.1: 정답률 77%

ahyes·2022년 12월 18일
0

[JS]프로그래머스 Lv.1

목록 보기
10/10
post-thumbnail

안녕하세요.
이어서 정답률 77% 문제를 풀어보겠습니다.

  1. 행렬의 덧셈
function solution(arr1, arr2) {
    for(let i = 0; i<arr1[0].length;i++){
        for(let j = 0; j < arr1.length; j++){
            arr1[j][i] += arr2[j][i]   
        }
    }
    return arr1;
}
  1. 직사각형 별찍기
process.stdin.setEncoding('utf8');
process.stdin.on('data', data => {
    const n = data.split(" ");
    const a = Number(n[0]), b = Number(n[1]);
    for(let i=0;i<b;i++){
        for(let j=0;j<a;j++){
            process.stdout.write("*")
        }
        process.stdout.write("\n")
    }
});

(추가!!) repeat도 사용할 수 있다.

process.stdin.setEncoding('utf8');
process.stdin.on('data', data => {
    const n = data.split(" ");
    const a = Number(n[0]), b = Number(n[1]);
    let h='';
    for(let i=0;i<b;i++){
        h='*'.repeat(a)
        console.log(h)
    }
});
profile
티스토리로 이사갑니다. https://useyhnha.tistory.com/

0개의 댓글