Lumpy Space Princess - Adventure Time

CODING

JS 와 SQL test 08

jongyung 2023. 4. 21. 12:33

“ 지연되는 프로젝트에 인력을 더 투입하면 오히려 더 늦어진다. ”

- Frederick Philips Brooks
Mythical Man-Month 저자
728x90

JS 

01. 다음의 결괏값을 작성하시오.

let i = 0;
let sum = 0;

while(i < 10){
    i = i+1;
    if( i % 3 == 0) sum -= i;
    if( i % 3 == 1) sum += i;
    if( i % 3 == 2) sum *= i 
}

console.log(sum)

02. 다음의 결괏값을 작성하시오.

let num = [10, 20, 30, 40, 50];
let i, max, min;
max = min = num[0];

for(i=0; i<5; i++){
    if(num[i] > max) max = num[i];
    if(num[i] < min) min = num[i];
}

console.log(max, min);

03. 다음의 결괏값을 작성하시오.

function func(begin, diff, n){
    cnt = 1;
    ret = begin;
    while(true){
        cnt += 1;
        ret *= diff;
        if(cnt == n) return ret;
    }
}

console.log(func(1, 3, 4));

04. 다음의 결괏값을 작성하시오.

let i = 0;
let sum = 0;
while(i < 10){
    i = i + 1;
    if(i % 2 == 0){
        continue
    }
    sum += i;
}

console.log(sum)

05. 다음의 결괏값을 작성하시오.

let num = [56, 4, 3, 65, 78];
let temp;

for(let i=0; i<1; i++){
    for(let j=0; j<num.length-i-1; j++){
        if(num[j]>num[j+1]){
            temp = num[j];
            num[j] = num[j+1];
            num[j+1] = temp;
        }
    }
}

console.log(num)

06. 다음의 결괏값을 작성하시오.

let num = [56, 4, 3, 65, 78];
let min = 9999;

for(let i=0; i<10; i++){
    if(min > num[i]){
        min = num[i];
    }
}

console.log(min)

07. 다음의 결괏값을 작성하시오.

let num = [3, 4, 5, 7, 8];
let temp;

for(let i=0; i<=3; i++){
    for(let j=i+1; j<=4; j++){
        if(num[i] < num[j]){
            temp = num[i];
            num[i] = num[j];
            num[j] = temp;
        }
    }
}

console.log(num);

08. 다음의 결괏값을 작성하시오.

let num = [1,2,3,4,5];
let sum = 1;

function func(arr){
    for(let i=0; i<arr.length; i++) {
        sum += arr[i];
    }

    for(let i=0; i<arr.length; i++){
        if(arr[i] % 2 == 0) sum -= arr[i];
    }
    return sum;            
}

console.log(func(num));

09. 다음의 결괏값을 작성하시오.

let num = ["0","1","2","3","4","5","6","7","8","9"];
let sum = 100;

for(let i=0; i<num.length; i++){
    num[i] = i+1;
}
for(let i=0; i<num.length; i++){
    if(i % 3 == 1){
        sum -= num[i];
    }
}
console.log(sum)

10. 다음의 결괏값을 작성하시오.

let arr = [1,2,3,4,5];
let temp = [1,2,4,6,8];
let idx = 0;
let flag = true;

for(let i=0; i<arr.length; i++){
    flag = false;
    if(arr[i] == temp[i]){
        flag = true;
    }
    if(!flag){
        temp[idx++] = arr[i];
        console.log(temp[idx]);
    }
}

11. 다음은 최솟값을 출력하는 예제이다. 밑줄에 적합한 표현을 작성하시오.

let num = [30,40,24,80,99];
let min = 9999;

for(let i=0; i<5; i++){
    if(min > num[i]){
        min = ________;
    }
}

console.log("최소값 : ", min);

12. 다음의 결괏값을 작성하시오.

let s1 = "Remember november";
let s2 = s1.slice(0, 3) + s1.slice(12, 16);
let s3 = "r AND you";

console.log(s2 + s3)

13. 다음의 결괏값을 작성하시오.

let x = 1;

console.log( !(x>0) );
console.log( x>0 || x<4 );
console.log( x<<2 );
console.log( x&2 );
console.log( x&3 );

14. 다음의 결괏값을 작성하시오.

let num = 0;
let i = 1;

while(i<=50){
    if(i%7 == 0){
        num += i;
    }
    i++;
}
console.log(num)

15. 다음의 결괏값을 작성하시오.

let result = 0;
for(let i=1; i<999; i++){
    if(i%3==0 && i%2 !=0){
        result = i;
    }
}
console.log(result);

16. 다음의 결괏값을 작성하시오.

function func(num){
    if(num <= 1){
        return 1;
    } else {
        return num + func(num - 2);
    }
}
function main(){
    let num = 5;
    console.log(func(num))
}
main();

17. 다음의 결괏값을 작성하시오.

let a=1, b=1, num;

for(let i=0; i<6; i++){
    num = a + b;
    a = b;
    b = num;
}
console.log(num)

18. 다음의 결괏값을 작성하시오.

function func(num1, num2){
    let res = 1;
    for(let i=0; i<num2; i++){
        res *= num1;
    }
    return res;
}
let res = func(2, 10);

console.log(res)

19. 다음의 결괏값을 작성하시오.

let a = func(4);

for(let i=0; i<a.length; i++){
    console.log(a[i]);
}

function func(n){
    let num = [];
    for(let i=0; i<n; i++){
        num[i] = i;
    }
    return num;
}

20. 다음의 결괏값을 작성하시오.

let a = 3, b = 4, c = 3, d = 5;

if( (a == 2 | a == c) & !(c > d) & (1 == b ^ c != d) ){
    a = b + c;
    if( 7 == b ^ c != a ){
        console.log(a);
    } else {
        console.log(b);
    }
} else {
    console.log(a + b)
}