Skip to content

Instantly share code, notes, and snippets.

@breakstorm
Created January 6, 2017 08:01
Show Gist options
  • Save breakstorm/24466b8be41f8667809185a769d6a0c8 to your computer and use it in GitHub Desktop.
Save breakstorm/24466b8be41f8667809185a769d6a0c8 to your computer and use it in GitHub Desktop.
home work
//예외처리
function checkArg(sArgs,sType){
for(i=0; i < sArgs.length; i++){
if(sArgs[i] !== sType) return false
}
return true
}
//1week_homework
//1번 문제 : 입력받은 값 까지의 홀수 출력
function getOdd(num){
for(i=1;i <= num; i = i+2){
console.log(i)
}
}
getOdd(10)
getOdd(5)
getOdd(21)
console.log("1번문제 END");
//2번 문제 : 사각형넓이 반환
function getRectArea(row,col){
//인지값이 숫자인지 확인 예외 처리 필요한가?
return row * col
}
console.log(getRectArea(10,4))
console.log("2번문제 END");
//3번 문제 : 삼각형의넓이 반환
function getTriangletArea(row,col){
return (row * col) / 2;
}
console.log(getTriangletArea(10,4))
console.log("3번문제 END");
//4번 문제 : 삼각형,사각형의 넓이를 배열에 반환받아서 리턴하라
function getArea(row, col){
var areaSet = [];
areaSet.push(getRectArea(row,col));
areaSet.push(getTriangletArea(row,col));
//var temp = areaSet.toString();
//console.log(temp);
return areaSet
}
getArea(10,4)
console.log("4번문제 END");
//5번 문제 : 배열 값 추가 및 삭제
var recentSearchWord = ["코드스쿼드","자바스크립트"]
function addWord(sArgs, sType){
return sArgs.push(sType)
}
function removeWord(sArgs, sType){
var index_num = sArgs.indexOf(sType)//{
//return sArgs[i] === text
//for(i=0; i < sArgs.lenth; i++)
//}
//)
//var index_num = sArgs.findIndex(isSame)
return sArgs.splice(index_num,1)
}
/*
function isSame(sArgs){
return sArgs === "자바스크립트"
}
*/
console.log(recentSearchWord)
addWord(recentSearchWord,"크롱크롱")
console.log(recentSearchWord)
removeWord(recentSearchWord,"코드스쿼드")
console.log(recentSearchWord)
console.log("5번문제 END")
//6번 문제 : 배열 값 추가2
function insertElement(sArgs,index_num,sType){
return sArgs.splice(index_num,0,sType)
}
insertElement(recentSearchWord,2,"James")
console.log(recentSearchWord)
insertElement(recentSearchWord,2,"Bond")
console.log (recentSearchWord)
console.log("6번문제 END")
//7번 문제 : 객체 접근
/*
1.name값 접근방법 : myObj.name
2.name값 변경방법 : myObj.name="diff value"
3.새로운 property 추가방법 : myObj.newproperty = "newThing"
4.특정 property 삭제방법 : delete myObj.newproperty
5.객체 사용상황 : 동일한 자료의 형태가 필요한경우
(전화번호부, 홈페이지 계정정보, 블로그등의 동일한 화면 ...)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment