css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <address>For leecho</address>
            
          
!
            
              /* 멋들어진 배경을 위해 */
body { background:#000; color:#0f0; font-size: 1.5em; line-height: 1.8; user-select: none; }
            
          
!
            
              (function() {
   "use strict";
   // @See Leecho
   /**
    * 배열에서 원하는 조건으로 뽑아내기
    * - 동일한 값일 경우, 먼저 나온 값을 먼저 보여줌
    * @param array {Array} 대상 배열
    * @param extractUnique {Boolean} 고유값이 필요한 지
    * @param isSortedByLeast {Boolean} 조금 반복된 것부터 정렬할 지
    * @param isStrictType {Boolean} 자료형을 구분할 지, (숫자/문자 구분)
    * @return {Array}
    */
   function extractArray(array, extractUnique, isSortedByLeast, isStrictType) {
      var result = [];
      var checker = {};
      // 배열 내 value 별 개수 세기
      for (var i = 0, m = array.length; i < m; i++) {
         var value = array[i];
         var keyName = value + (isStrictType === true ? typeof value : "");
         if (
            !checker[keyName] ||
            !checker[keyName].count ||
            typeof checker[keyName].count !== "number"
         ) {
            checker[keyName] = { value: value, count: 1 };
            continue;
         }
         checker[keyName].count++;
      }

      var isPassCondition = function(value) {
         // extractUnique
         // 고유한 것을 뽑아내는 것이면, 1보다 크면 넘김
         // 중복된 것을 뽑아내는 것이면, 1이거나 작으면 넘김
         return extractUnique === true ? value > 1 : value <= 1;
      };

      // keyName 과 count 로 분리하여 객체로 결과용 배열에 담기
      for (var keyName in checker) {
         if (checker.hasOwnProperty(keyName)) {
            if (
               !checker[keyName].count ||
               isPassCondition(checker[keyName].count)
            ) {
               continue;
            }
            var element = {};
            element.value = checker[keyName].value;
            element.count = checker[keyName].count;
            result.push(element);
         }
      }

      // 결과 배열 내에, count 를 높은 순으로 재정렬
      result.sort(function(a, b) {
         return isSortedByLeast === true
            ? // 낮은 순 중복 우선 정렬인지
              a.count - b.count
            : b.count - a.count;
      });

      // 결과 배열의 객체 내부 keyName 으로 객체를 치환
      for (var i = 0, m = result.length; i < m; i++) {
         result[i] = result[i].value;
      }

      // 결과 반환
      return result;
   }

   var body = document.getElementsByTagName("body")[0];
   function print(key, message) {
      var element = document.createElement("code");
      console.log(key, message);
      element.innerHTML = ["[ ", key, " ] ", "( ", message, " )"].join("");
      body.appendChild(element);
      body.appendChild(document.createElement("br"));
   }
   var _t = extractArray;
   var a1 = [1, 1, "1", 3, "1", 5, 5, 5, 5, 2, 4, 5, 2, 3, 2, "1", 3, 0, 6];
   var a2 = [1, "2", 2, 3];
   var a3 = [1, 2, 3];
   var a4 = [];
   print("a1", a1);
   print("_(a1)", _t(a1));
   // 고유값 정렬
   print("_(a1, true, null, false)", _t(a1, true, null, false));
   // 중복을 최소순으로 정렬
   print("_(a1, false, true, false)", _t(a1, false, true, false));

   // String 과 Number 구분
   print("_(a1, null, null, true)", _t(a1, null, null, true));

   print("a2", a2);
   print("_(a2)", _t(a2));
   // String 과 Number 구분
   print("_(a2, null, null, true)", _t(a2, null, null, true));

   print("a3", a3);
   print("_(a3)", _t(a3));

   print("a4", a4);
   print("_(a4)", _t(a4));
})();

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console