편집 기록

편집 기록
  • 프로필 편집요청빌런님의 편집
    날짜2020.02.07

    $.unique()로 중복 제거가 안되네요.


        <ol>
            <li class="horses">Thoroughbred</li>
            <li class="horses">Arabian</li>
            <li class="horses">Brlgian</li>
            <li class="horses">Percheron</li>
            <li class="horses">Arabian</li>
            <li class="animals">Brlgian</li>
            <li class="animals">dog</li>
            <li class="animals">cat</li>
        </ol>
        <ul id="animals"></ul>
    
    <script>
        $(document).ready(function(){
            var animals = $('li.animals').get(); //.animals클래스 값을 배열로  변수대입
            var horses = $('li.horses').get(); //.horses클래스 값을 배열로 변수대입
            var tmp = $.merge( animals, horses); //첫번째 클래스 배열과 2번째 클래스 배열을 합쳐  tmp 변수에 대입
            tmp = $.unique(tmp); //tmp 변수의 중복된 값을 삭제한다
            $('#animals').append($(tmp).clone()); //ul 의 id 값에  변수 tmp 를 추가한다. 
    
        });
        /* 예상 결과 
            Thoroughbred
            Arabian
            Brlgian
            Percheron
            dog
            cat
            */
    
        /*출력된 결과값   
            Thoroughbred
            Arabian
            Brlgian
            Percheron
            Arabian
            Brlgian
            dog
            cat
    
            */
    </script>
    
    

    스크립트 주석부분은 제가 해석한 건데 출력 예상결과로는 중복값이 다 삭제된 채로 출력이되어야 된다구 생각이 되는데 결과값은 중복값 포함되서 출력이 되었습니다....해석이 잘못된 부분이 있을까요?

  • 프로필 알 수 없는 사용자님의 편집
    날짜2020.02.07

    질문있습니다 ~!


    <ol>
        <li class="horses">Thoroughbred</li>
        <li class="horses">Arabian</li>
        <li class="horses">Brlgian</li>
        <li class="horses">Percheron</li>
        <li class="horses">Arabian</li>
        <li class="animals">Brlgian</li>
        <li class="animals">dog</li>
        <li class="animals">cat</li>
    </ol>
    <ul id="animals"></ul>
    
    
    $(document).ready(function(){
        var animals = $('li.animals').get(); //.animals클래스 값을 배열로  변수대입
        var horses = $('li.horses').get(); //.horses클래스 값을 배열로 변수대입
        var tmp = $.merge( animals, horses); //첫번째 클래스 배열과 2번째 클래스 배열을 합쳐  tmp 변수에 대입
        tmp = $.unique(tmp); //tmp 변수의 중복된 값을 삭제한다
        $('#animals').append($(tmp).clone()); //ul 의 id 값에  변수 tmp 를 추가한다. 
    
    });
    /* 예상 결과 
        Thoroughbred
        Arabian
        Brlgian
        Percheron
        dog
        cat
        */
    
    /*출력된 결과값   
        Thoroughbred
        Arabian
        Brlgian
        Percheron
        Arabian
        Brlgian
        dog
        cat
    
        */
    

    스크립트 주석부분은 제가 해석한 건데 출력 예상결과로는 중복값이 다 삭제된 채로 출력이되어야 된다구 생각이 되는데 결과값은 중복값 포함되서 출력이 되었습니다....해석이 잘못된 부분이 있을까요?