Pen Settings

HTML

CSS

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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <address>For leecho</address>
              
            
!

CSS

              
                /* 멋들어진 배경을 위해 */
body { background:#000; color:#0f0; font-size: 1.5em; line-height: 1.8; user-select: none; }
              
            
!

JS

              
                (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

Console