<Google Jamboard>

COMP 2조 - Google Jamboard

⚡ 개념 정리하기 !

  1. 콤프 회원 한 명의 정보를 저장하는 변수를 만들려면 어떻게 해야할까요?

    1. 입력되는 정보는 이름, 나이, 학과, 그리고 1학년인지의 여부입니다.

      boolean, integer, string 을 모두 사용하세요!

    2. object 개념을 활용하세요! (C로 치면 struct나 array, Python으로 치면 dict나 list 등)

    const compMember = {
    	name: "Kim Amugae",
    	age: 20,
    	department: "CAU COMP",
    	isGrade1: true,
    };
    
  2. 1번에서 만든 변수로 여러 사람의 정보를 담으려면 어떻게 해야할까요?

    1. objectarray의 개념을 활용하세요!

      Hint❗ 콤프 사람들에게 0부터 15까지 한명씩 번호를 붙인다고 가정해봅시다!

    ㄴ 코드를 작성하지 않고 모형도를 그리기만 해도 됩니다!

// 1. Array에 Object를 직접 생성
const members = [
  { name: "콤프1", age: 20, major: "컴퓨터 공학", is_freshman: true },
  { name: "콤프2", age: 21, major: "경영학", is_freshman: false },
  { name: "콤프3", age: 19, major: "영어문학", is_freshman: true }
// .......
];

// 2. object를 먼저 생성 후 Array에 대입
const compMembers = [
	compMember0,
	compMember1,
	// ...
	compMember15,
];

// 3. 빈 어레이를 생성 후 push()
let compMembers = []; // Create an empty array
for (let i = 0; i <= 15; i++) { // [0, 15] range
	compMembers.push({
			name: undefined,
			age: undefined,
			department: undefined,
			isGrade1: undefined,
	});
}
  1. 2번에서 만든 변수를 반환하는 함수를 작성한다면, 어떻게 작성해볼 수 있을까요?

    ㄴ 3번은 정답이 없습니다! 고민하면서 실력이 늘 거에요 ㅎㅎ

// 전체 멤버를 반환하는 함수
function getEntireCompMembers() {
	return compMembers;
}

// 인덱스를 받아 해당하는 번째만 반환하는 함수
function getCompMember(idx) {
	return compMembers[idx];
}

// 멤버를 받아 멤버의 이름을 출력하는 함수
function getCompMemberName(member) {
	return member.name;
}

// ... 주르륵

⚡ 토론해보아요 !

  1. 두 수가 주어졌을 때, 두 값 중 큰 값, 작은 값, 그리고 일치 여부를 각각 반환하려면 어떻게 해야할까요? (단, 하나의 객체 내에서 모두 처리하도록 해요)

      Hint❗ 노마드 코더 강의 중 calculator 변수 선언 내용을 참고하세요!
    
// if ~ else
const calc = { 
  maxcalc: function (a,b){
      if (a>b)
				return a;
      else if (a<b)
				return b;
      else 
				return "The two numbers have the same values"
	},
  minclac: function (a,b){
	    if (a>b)
				return b;
			else if (a<b)
				return a;
			else 
				return "The two numbers have the same values"
	},
	samecalc: function (a,b) {
     if(a==b)
				return true;
     else
			return false;
	 }
}

// 축약형.
let compare = {
	x: 27, y: 36,
	getLarger: function() {
		return isSame() ? undefined : ((x > y) ? x : y);
	},
	getSmaller: function() {
		return isSame() ? undefined : ((x < y) ? x : y);
	},
	isSame: function() {
		return x === y;
	}
};
  1. 값이 두 개가 아니라 세 개가 주어졌다면 어떻게 해결해야 할까요?

    ㄴ 이 문제는 웹 개발 보다는 논리적 사고를 중점으로 보는 문제에요!

    조원들과 상의해보세요😃

max or min 함수를 사용하고,
없으면 값을 두 개씩 비교해서 조건문을 중첩해서 사용한다.

// 이런 식으로...
function() {
	if (a>b)
if (c>a)
return c
else if 
}
// 만약 순서대로 정렬할 수 있다면 다음과 같은 방법 사용 가능
let complexCompare = {
	x: 28, y: 37, z: 12,
	getList(): function() { 
		let arr = [x, y, z];
		arr.sort();		
		return arr;
 },
	getLargest(): function() {
		return hasSame(2) ? undefined : getList()[2];
	}
	getSmallest(): function() {
		return hasSame(0) ? undefined : getList()[0];
	},
	isSame(): function() {
		return x === y && y === z;
	},
	hasSame(idx): function() {
		return getList()[1] === getList()[idx];
	}
}

Screenshot_20230503_163608_Samsung Notes.jpg

a, b, c가 모두 다르다면 간단하게 비교할 수 있지만, 둘이 같거나 셋이 같은 경우가 있을 수 있기에 경우의 수를 모두 따져보아야 한다.