'UI'



코드

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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>배열~!</title>
<script type="text/javascript">
    var jArr = new Array();
    
    function arrAdd(num){
        jArr.push(num); //값을 넣어준 후
        document.getElementById("result").innerHTML = jArr.toString(); // 현재 배열에 있는 값 toString으로 출력
    }
    function arrShift(){
        jArr.shift(); // 값을 왼쪽부터 뺀 후
        document.getElementById("result").innerHTML = jArr.toString(); // 현재 배열에 있는 값 toString으로 출력
    }
    function arrPop(num){
        jArr.pop(); // 값을 맨 뒤에서 부터 뺀 후
        document.getElementById("result").innerHTML = jArr.toString();// 현재 배열에 있는 값 toString으로 출력
    }
    function arrReverse(){
        document.getElementById("result").innerHTML = jArr.reverse(); //반대로 뒤집어서 출력
    }
    function arrSort(){
        document.getElementById("result").innerHTML = jArr.sort((a,b) => a-b); //오름차순으로 정렬(sort)
                                                                              //내림차순 : b-a
    }
</script>
</head>
<body>
    <table>
        <tr>
            <td>
                <input type="text" id="text">
                <input type="button" id="arrAdd" value="배열에 추가하기" onclick="arrAdd(text.value)">
            </td>
        </tr>
        <tr>
            <td>
                현재 배열의 값: <span id="result"></span>
            </td>
        </tr>
        <tr>
            <td>
                <input type="button" id="Shift" value="Shift로 꺼내기"
                        style="width: 45%; height: 20px;" onclick="arrShift()">
                <input type="button" id="Pop" value="Pop으로 꺼내기"
                        style="width: 45%; height: 20px;" onclick="arrPop()">
            </td>
        </tr>
        <tr>
            <td>
                <input type="button" id="Recerse" value="Reverse로 뒤집기"
                        style="width: 45%; height: 20px;" onclick="arrReverse()">
                <input type="button" id="Sort" value="Sort로 정렬하기"
                        style="width: 45%; height: 20px;"onclick="arrSort()">
            </td>
        </tr>
    </table>
</body>
</html>
cs