PuTTY로 aws ec2로 만든 리눅스 환경 접속하기

AWS STUDY

  1. PuTTY로 aws ec2로 만든 리눅스 환경 접속하기

  2. ec2에-npm-설치

  3. express설치하고 helloworld 출력하기 feat 포트 열기


ec2 만들기

aws의 ec2와 putty를 이용하여 리눅스에 개발공간을 만들고 연결하기
aws가입 필요.

인스턴스 생성

가난한 저는 프리티어의 ec2를 생성하여 사용합니다.

리눅스 초짜 리알못은 일단 아마존 리눅스를 사용하겠습니다.

1. 우측 상단 내 계정 - AWS Management Console을 클릭

image

javascript-sort

Javascript Array sort

기본

오름차순

1
2
3
const array = ['z', 'c', 'a'];
array.sort();
console.log(array);

image

javascript-3

원시 값과 객체의 비교

원시 타입 vs 객체 타입

원시타입 : immutable value
객체타입 : mutable value
원시 값을 변수에 할당하면 변수에는 실제 값이 저장
객체를 변수에 할당하면 변수에 참조 값이 저장
Pass by value : 원시 값을 갖는 변수를 다른 변수에 할당하면 원본의 원시 값이 복사
Pass by referencce : 객체를 가리키는 변수를 다른 변수에 할당하면 원본의 참조 값이 복사

codility-3-2-FrogJmp

FrogJmp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29


A small frog wants to get to the other side of the road. The frog is currently located at position X and wants to get to a position greater than or equal to Y. The small frog always jumps a fixed distance, D.

Count the minimal number of jumps that the small frog must perform to reach its target.

Write a function:

function solution(X, Y, D);

that, given three integers X, Y and D, returns the minimal number of jumps from position X to a position equal to or greater than Y.

For example, given:
X = 10
Y = 85
D = 30

the function should return 3, because the frog will be positioned as follows:

after the first jump, at position 10 + 30 = 40
after the second jump, at position 10 + 30 + 30 = 70
after the third jump, at position 10 + 30 + 30 + 30 = 100

Write an efficient algorithm for the following assumptions:

X, Y and D are integers within the range [1..1,000,000,000];
X ≤ Y.

Copyright 2009–2019 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.

설명

X : 시작 위치
Y : 도착 위치
D : 증가량

X+nD > Y의 n을 구하기
도착위치에서 시작위치를 뺀 후 증가량 D로 나누기
다른 언어의 경우 기본적으로 정수형 연산이기 때문에 나머지가 있으면 몫+1 이지만
javascript는 기본적으로 모든 숫자의 연산이 정수가 아닌 실수형이기 때문에 올림으로 계산하면 됨

코드

1
2
3
4
function solution(X, Y, D) {
// write your code in JavaScript (Node.js 8.9.4)
return Math.ceil((Y - X) / D);
}

결과

image

codility Lesson3 TapeEquilibrium

TapeEquilibrium

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45


A non-empty array A consisting of N integers is given. Array A represents numbers on a tape.

Any integer P, such that 0 < P < N, splits this tape into two non-empty parts: A[0], A[1], ..., A[P − 1] and A[P], A[P + 1], ..., A[N − 1].

The difference between the two parts is the value of: |(A[0] + A[1] + ... + A[P − 1]) − (A[P] + A[P + 1] + ... + A[N − 1])|

In other words, it is the absolute difference between the sum of the first part and the sum of the second part.

For example, consider array A such that:
A[0] = 3
A[1] = 1
A[2] = 2
A[3] = 4
A[4] = 3

We can split this tape in four places:

P = 1, difference = |3 − 10| = 7
P = 2, difference = |4 − 9| = 5
P = 3, difference = |6 − 7| = 1
P = 4, difference = |10 − 3| = 7

Write a function:

function solution(A);

that, given a non-empty array A of N integers, returns the minimal difference that can be achieved.

For example, given:
A[0] = 3
A[1] = 1
A[2] = 2
A[3] = 4
A[4] = 3

the function should return 1, as explained above.

Write an efficient algorithm for the following assumptions:

N is an integer within the range [2..100,000];
each element of array A is an integer within the range [−1,000..1,000].

Copyright 2009–2019 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.

방법

배열의 요소를 둘로 나누어 좌측 합과 우측합의 차를 절대값으로 계산하여 가장 작은 값을 찾는다.
좌측은 첫 요소부터 마지막요소를 제외한 나머지 요소의 합까지이며
우측은 첫 요소를 제외한 나머지의 합부터 마지막 요소까지
A[0] = 3
A[1] = 1
A[2] = 2
A[3] = 4
A[4] = 3
일 때,
3+1+2+4+5 = 13 이며,
|3 - (1+2+4+3)| 부터 |(3+1+2+4)-3|까지 이므로
마지막 요소는 좌측의 합이 아니기 때문에 반복문은 A.length-1

코드

1
2
3
4
5
6
7
8
9
10
11
12
13
14
function solution(A) {
const getSum = (accumulator, currentValue) => accumulator + currentValue;
let right = A.reduce(getSum);
let left = 0;
let min = 10001;
for (let i = 0; i < A.length - 1; i++) {
left += A[i];
right -= A[i];

min = Math.min(Math.abs(left - right), min);
}

return min;
}

결과

image

javascript-2

제어문

주어진 조건에 따라 블록을 실행하거나 반복 실행 할 때 사용
일반적 코드의 실행 순서를 인위적으로 제어

블록문

0개 이상의 문을 중괄호로 묶은 것
자바스크립트에서는 하나의 실행 단위로 취급
단독으로 사용가능하나 일반적으로 제어문, 함수 선언문 등에서 사용

Javascript-1

자바스크립트 개발 환경과 실행 방법

자바스크립트 = ES + Web API
Node.js : ES + Node.js API

자바스크립트는 브라우저에서 HTML, CSS와 함께 실행
렌더링엔진 : HTML, CSS
자바스크립트 엔진 : 자바스크립트

HTML 파서는 script 태그를 만나면 DOM 생성 프로세스를 중지하고 자바스크립트 엔진으로 제어 권한을 넘김
자바스크립트의 실행이 완료되면 다시 HTML 파서로 제어권한을 넘겨서 브라우저가 중지했던 시점부터 DOM생성을 재개
DOM이 완성되지 않은 상태에서 자바스크립트가 DOM을 조작하면 애러가 발생할 수 있다.

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×