JS 100제 문제 70 행렬 곱하기

이민정·2021년 4월 13일
0

JS100제

목록 보기
60/66

<풀이 코드>


	const b = [[1, 0],[0, 3]];
	
	function sol(a,b){
		var result = [[,],[,]];
		
		if(a[1].length == b[0].length){
			result[0][0] = a[0][0]*b[0][0] + a[0][1]*b[1][0];
			result[0][1] = a[0][0]*b[0][1] + a[0][1]*b[1][1];
			result[1][0] = a[1][0]*b[0][0] + a[1][1]*b[1][0];
			result[1][1] = a[1][0]*b[0][1] + a[1][1]*b[1][1];
			
			return result;
		}else{
			return "-1";
		}
	}
	
	console.log(sol(a,b));
profile
공부하자~!

0개의 댓글