Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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

              
                
              
            
!

CSS

              
                
              
            
!

JS

              
                
var array1 = ['午', '辰', '卯', '子', '申'];
var orderRule1 = ['子', '丑', '寅', '卯', '辰', '巳', '午', '未', '申', '酉', '戌', '亥'];

array1.sort(function(a, b) {
    return orderRule1.indexOf(a) - orderRule1.indexOf(b);
});

console.log(array1);
/* ["子","卯","辰","午","申"] */
/* sort で並び替えできる例。これができると簡単でよい */







var list = {"date":[
  ["1","水曜 午前"],
  ["2","水曜 午後"],
  ["3","木曜 午前"],
  ["4","木曜 午後"],
  ["5","金曜 午前"],
  ["6","金曜 午後"],
  ["7","土曜 午前"],
  ["8","土曜 午後"],
  ["9","日曜 午前"],
  ["10","日曜 午後"],
  ["11","月曜 午前"],
  ["12","月曜 午後"],
  ["13","火曜 午前"],
  ["14","火曜 午後"]
]};

var arrDaysOrder = [
  "月曜",
  "火曜",
  "水曜",
  "木曜",
  "金曜",
  "土曜",
  "日曜"
];

list.date.sort(function(a, b) {
    return arrDaysOrder.indexOf(a[1]) - arrDaysOrder.indexOf(b[1]);
});
console.log(list);
/*


*/
/* 完全一致のため arrDaysOrder の値では一致せず、並び替えできない */








var data2 = [
    [ 4, "S", "太郎", 97 ],
    [ 3, "C", "花子", 16 ],
    [ 1, "B", "夏樹", 77 ],
    [ 7, "S", "菊子", 90 ],
    [ 2, "S", "春子", 100],
    [ 6, "A", "冬秋江", 89 ],
    [ 5, "A", "春冬樹", 89 ]
];
var orderRule2 = ['春子', '夏', '寅', '卯', '辰', '巳', '午', '未', '申', '酉', '戌', '亥'];

// 降順
data2.sort(function(a, b) {
    return orderRule2.indexOf(b[2]) - orderRule2.indexOf(a[2]);
});
console.log(data2);
/* 完全一致のため「春子」が上になるだけ */



$.each(data2, function(key, value){
    if(value[2].match(/冬/)){
        console.log(key + ' : ' + value);
        data2.sort(function(a, b) {
            return orderRule2.indexOf(b[2]) - orderRule2.indexOf(a[2]);
        });
    }
});
/* 部分一致でピックアップはできそう */







var data3 = [
    [ 4, "S", "太郎", 97 ],
    [ 3, "C", "花子", 16 ],
    [ 1, "B", "夏樹", 77 ],
    [ 7, "S", "菊子", 90 ],
    [ 2, "S", "春子", 100],
    [ 6, "A", "冬秋春江", 89 ],
    [ 5, "A", "春冬樹", 89 ]
];

var result3A1 = $.map(data3, function(value, index) {
  
  if(value[2].indexOf('春')) {
    return null;
  } else {
    return [value];
  }
  
});
var result3A2 = $.map(data3, function(value, index) {
  
  if(!value[2].indexOf('春')) {
    return null;
  } else {
    return [value];
  }
  
});

console.log(result3A1);
console.log(result3A2);
console.log(result3A1.concat(result3A2));
/* 先頭部分一致で並び替えできた */








var list4 = {"date":[
  ["1","水曜 午前"],
  ["2","水曜 午後"],
  ["3","木曜 午前"],
  ["4","木曜 午後"],
  ["5","火曜 午前"],
  ["6","火曜 午後"]
]};


var result4A = $.map(list4.date, function(value, index) {
  
  if(value[1].indexOf('火曜')) {
    return null;
  } else {
    return [value];
  }
  
});
var result4B = $.map(list4.date, function(value, index) {
  
  if(!value[1].indexOf('火曜')) {
    return null;
  } else {
    return [value];
  }
  
});

console.log(result4A);
console.log(result4B);
console.log(result4A.concat(result4B));
/*
*/
/* 上と同じ感じ */
              
            
!
999px

Console