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

              
                .wrapper
  h1.title 配列をn個ずつ抜き出す

  .question [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]を3個ずつ抜き出す

  button#run.button(type="button") 実行
  
  #result.result
  
  

              
            
!

CSS

              
                .wrapper
  padding 24px
  
.title
  font-size 1.6rem
  
.question
  margin-bottom 24px
  
.result
  line-height 1.6
  
.button
  margin-bottom 24px
              
            
!

JS

              
                /**
 * 配列をn個ずつ抜き出す
 * 連想配列は処理できない
 */
class ArraySlice {
  /**
   * @param collection {array} - 配列
   * @param every {number} - n個(1以上の正数)
   */
  constructor (collection, every) {
    this._count = 0
    this._collection = collection
    this._every = every
  }

  /**
   * 配列の抜き出し
   * @return {T[]}
   */
  get () {
    const index = this._every * this._count
    this._count++
    return this._collection.slice(index, index + this._every)
  }

  /**
   * 次の抜き出す配列が存在するか
   * @return {boolean}
   */
  hasNext () {
    const index = this._every * this._count
    return this._collection.slice(index, index + this._every).length > 0
  }
}

const result = document.getElementById('result')
const collection = new ArraySlice([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 3)

document.getElementById('run').addEventListener('click', ()=>{
  let txt = []
  let count = 1
  
  while(collection.hasNext()){
    const res = collection.get()
    let arr = []
    let _txt = `${count}回目: [`
    
    for(let i = 0, iLen = res.length; i < iLen; i++){
      arr.push(res[i])
    }
    
    _txt += `${arr.join(', ')}]`
    txt.push(_txt)
    count++
  }
  
  result.innerHTML = txt.join('<br>')
})
              
            
!
999px

Console