cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

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.

            
              <script src='https://scottdalessandro.github.io/jasmine-total/js/jasmine-suite.min.js'></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/marked/0.3.6/marked.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

<div class='container-fluid'>
  <!-- Nav tabs -->
  <ul class="nav nav-tabs" id="myTab" role="tablist">
    <li class="nav-item">
      <a class="nav-link active" data-toggle="tab" href="#problem" role="tab">Challenge & Examples</a>
    </li>
    <li class="nav-item">
      <a class="nav-link" data-toggle="tab" href="#testspecs" role="tab">Test Specs</a>
    </li>
    <li class="nav-item">
      <a class="nav-link" data-toggle="tab" href="#run-specs" role="tab">Run Specs</a>
    </li>
  </ul>

  <!-- Tab panes -->
  <div class="tab-content">
    <div class="tab-pane active" id="problem" role="tabpanel">
      <div class='jumbotron' id="probjumbo">
      </div>
    </div>
    <div class="tab-pane" id="testspecs" role="tabpanel">
      
      <h4>SPECS </h4>
      <pre> 
        <code id="codeblock" class="language-javascript"> 
        </code> 
      </pre>
     
    </div>
    <div class="tab-pane" id="run-specs" role="tabpanel">

    </div>
  </div>

</div>


<script id="test-data">
/*
STARTPROBLEM
## Rotate

Write a function that will rotate an array to the right by a certain number of "steps".  

For example, the array to rotate is: `[1,2,3,4,5,6,7]` and will be rotated 3 "steps". The final array will look like: `[5,6,7,1,2,3,4]`.  Notice the position of each index is shifted to the right by three places. The first argument to the rotate function is the array to rotate; the second argument is a number of​ steps.

#### Examples

- **INPUT**: `rotate([22, 11, 500, 92], 2);`
- **OUTPUT**: `[500, 92, 22, 11];`



- **INPUT**: `rotate([11, 15, 28, 9, 10], 0)`
- **OUTPUT**: `[11, 15, 28, 9, 10]`


ENDPROBLEM
*/       
 
/// STARTSPECS
describe('rotate', function() {
  it('is a function', function() {
    expect(typeof rotate).toBe('function');
  });

  it('returns an array', function() {
    expect(Array.isArray(rotate([], 0))).toBe(true);
  });

  it('shifts all the values in the array', function() {
    expect(rotate([22, 11, 500, 92], 2)).toEqual([500, 92, 22, 11]);
    expect(rotate([11, 15, 28, 9, 10], 0)).toEqual([11, 15, 28, 9, 10]);
    expect(rotate([7, 8, 9, 10, 11], 5)).toEqual([7, 8, 9, 10, 11]);
  });
});
/// ENDSPECS
</script>

<script>


   
    var testData = document.getElementById("test-data").innerHTML;
    var probData = [], specData = [];
    var insideProb = false, insideSpec = false;

    testData.split(/\n/).forEach(line => {
      if(line.indexOf("STARTPROBLEM") >= 0) {
        insideProb = true;
      } else if(line.indexOf("ENDPROBLEM") >= 0) {
        insideProb = false;
      } else if(line.indexOf("STARTSPECS") >= 0) {
        insideSpec = true;
      } else if(line.indexOf("ENDSPECS") >= 0) {
        insideSpec = false;
      }
      if(insideProb) { probData.push(line) };
      if(insideSpec) { specData.push(line) };
    });

    probHTML = marked(probData.slice(1).join("\n"));
    document.getElementById("probjumbo").innerHTML = probHTML;  
    specHTML = "\n" + specData.slice(1).join("\n");
    document.getElementById("codeblock").innerHTML = specHTML;  

    $(document).ready(function() { 
      document.getElementById('run-specs').appendChild(document.getElementsByClassName('jasmine_html-reporter')[0]);
    });


</script>
            
          
!
            
              /* Write Code Here */












//EXAMPLE TESTS

rotate([22, 11, 500, 92], 2);
//Output: [500, 92, 22, 11]
            
          
!
999px
Loading ..................

Console