Immersive review

미숙한 초보 코딩.Js·2019년 8월 29일
0

immersive

목록 보기
16/22

1

var x = 30;

function get(x) {
  return x;
}
function set(value) {
  x = value;
}

set(10);
var result = get(20);

/*
x 의 값은 무엇인가?

풀이
처음에는 30을 하였는데 한번 실행 하였을때 set이 실행되면서 전역의 x 가
10으로 바뀌어 버립니다.

x = 10;
*/

#5

what is the result after running the code below

var x = 10;
var strangeAdd = function(y) {
  var x = 20;
  return this.x + y;
};

result = strangeAdd(10);

/*
	풀이
    처음에 답을 30을 하였는데 this가 함수형일때 전역의 x값을 들고와서
    결과는 20이 됩니다.
*/

#9

what is the result after running the code below x

var obj1 = { x: 10 };
var obj2 = Object.create(obj1);

var obj3 = Object.create(obj2);

obj2.x = 20;

var result = obj3.x + 10;

/*
	풀이
    result 값을 부를 때에는 이미 obj2.x 로 인하여 값이 바뀌어서 답은 30입니다.
*/

#11

What is the Big O time complexity for retrieving the value at a 
specific index in a linked list?

O(1) constant 
O(log n) Logarithmatic
O(n) Linear
O(n^2)
/*
	풀이
   	linked list에서 값을 찾기 위해서는 처음 해드부터 순차적으로 돌아야해서
    Linear하게 돌아야 합니다.
*/

#12

What is the worst case Big O time complexity of inserting a value 
into a binary search tree?

O(1) constant
O(log n) Logarithmatic 
O(n) Linear
O(n^2)

/*
	풀이
    BST에서도 값을 찾기 위해서는 처음 루트부터 children 을 순차적으로 
    돌아야 합니다.
   	Linear
*/

#13

What is the best case time complexity of looking up the value of 
a key in a hash table?

O(1) constant
O(log n) Logarithmatic
O(n) Linear
O(n^2)

/*
	풀이
    hashtable에서는 자신만의 key 가 있기때문에 값을 바로 찾을수 있어서
    constant입니다.
*/

#15

after running the code below what message will be eventually 
be alerted and after how long?

var name = "Window";
var alice = {
  name: "Alice", //TODO:
  sayHi: function() {
    //TODO:
    alert(this.name + " says hi");
  }
};
var bob = { name: "Bob" };
setTimeout(alice.sayHi.call(bob), 1000);

/*
	풀이
    alice.sayHi.call(bob)을 통해서 this를 bob으로 해놓고 call은 
    즉시 실행시켜주어서 `Bob says hi,immediately` 입니다.
*/

#16

after running the code below what message will be eventually 
be alerted and after how long?

var name = "Window";
var alice = {
  name: "Alice",
  sayHi: function() {
    //TODO:
    alert(this.name + " says hi");
  }
};
var bob = { name: "Bob" };

alice.sayHi.bind(bob);

setTimeout(alice.sayHi(), 1000);

/*
	풀이
   	alice.sayHi.bind(bob)은 따로 값을 가지고 있는것 같고
    alice.sayHi()를 통해서 불러서 Alice says hi 인것 같습니다.
*/

#18

After the following//TODO: what will be the value of x.foo?

var x = { foo: 3 }; //TODO:
var y = x;
y = 2;

/*
	풀이
    객체는 참조되지만 `y = 2` 를 통해서 값을 바꾸지는 못합니다.
*/

#19

After the following code runs, what will be the value of player.score?

var player = { score: 3 };
function doStuff(obj) {
  obj.score = 2;
  obj = undefined;
}
doStuff(player);

/*
	풀이
    obj로 player을 복사해와서 함수안에서 값을 2로 바꿔서 값이 2가 됩니다.
*/

#20

`users` table:

| id  | name  |
| --- | ----- |
| 7   | Alice |
| 8   | Bob   |
| 9   | Carl  |

`pets` table:

| id  | name    | owner_id |
| --- | ------- | -------- |
| 2   | Henry   | 7        |
| 3   | Fido    | 8        |
| 4   | Tofu    | 7        |
| 2   | Muggles | NULL     |

Write a query to select all users (and all their columns) that own at least one pet.
	 
select your answer *
SELECT * FROM USERS;
SELECT * FROM USERS u OUTER JOIN PETS p ON u.id = p.owner_id;
SELECT * FROM USERS u INNER JOIN PETS p ON u.id = p.owner_id;
SELECT * FROM USERS u LEFT JOIN PETS p ON u.id = p.owner_id;

/*
	풀이
    한마리 정도의 애완견을 가진사람을 원하기에 
    LEFT JOIN을 하게된다면 'Muggles'까지 다 대리고 오기때문에
    INNER JOIN을 이용해서 같은 것들만 추출 해냅니다.
*/

#24

Now, imagine that you have a local repository, 
but other team members have pushed changes into the remote repository.
What Git operation would you use to download those changes into your 
working copy? 

checkout 
commit
export
pull
update

/*
	풀이
    제가 작업한 것을 다른 팀원이 받기 위해서는 'pull'을 이용해 땡겨올수있다
*/

#26

Which of these terms best describe Git?

Issue Tracking System // (문제 추적시스템)
Distributed Version Control System // (분산 제어 시스템) - 사람들에게 배포가능
Integrated Development Environment // (통합 개발 환경)
Web-Based Repository Hosting Service //( 웹 기반 레포 호스팅 서버)

/*
	답은 Distributed Version Control System
    4번과 헷갈렷는데 사람들에게 분산 제어 시스템이 더 가까워서 선택하였습니다.
*/
profile
힘들땐 블로그 하나더 적자!!![ Suyang ]

0개의 댓글