JSFiddle - React, Tailwind, and code Playground

by pertrai1

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.0.0/jasmine-html.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jasmine/2.0.0/jasmine.js"></script>
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/jasmine/2.0.0/jasmine.css">
<title>Jasmine Spec Runner</title>

CSS

How about jasmine JS as an external resource??

I thought the spec was just: charAt, substring + for

/*
I got it working with a for loop


here ->

function trim(string){
  var len = string.length,
      i = 1,
      start = 0,
      end = 0,
      sdone = false,
      edone = false;
  
  if (typeof string != "string")
    return "";
  
  for(;i<len; i++ ){
    if (string.charAt(i) == " " && !sdone) {
      start = i + 1;
    } else { sdone = true; }
    if (string.charAt(len - i) == " " && !edone){
      end = i;
    } else {  edone = true; }
  }
  return string.substring(start, string.length - end);
}

console.log(trim("    somthing ssdfsdfd sfsf      "));
console.log(trim("    somthing"));
console.log(trim("somthing"));


*/

Hey Tom, it

JavaScript

function trim (str) {
    while(str.charAt(0) == " ") {
        //this loop loops through the first set of spaces at the begining. breaks when there is no more spaces
        str = str.substring( 1, str.length );
    };
    while( str.charAt(str.length-1) === " "  ) {
    //this loop will take the spaces at the end
        str = str.substring( 0 , str.length-1 );
    }    
    return str;
}

describe("trim", function() {
    
  it("trim method should be implemented", function() {
    expect(trim).toBeDefined();
  });
 
  it("trim characters at the begining and at the end not in the middle", function() {
    expect( trim("   asd")  ).toEqual("asd");
    expect( trim("   asd") ).toEqual("asd");;
    expect( trim("   don pedro                         ") ).toEqual( "don pedro" );
    expect( trim("   my javascript  ")  ).toEqual( "my javascript" );
    expect( trim("   s o m e  s p a c e s  ")  ).toEqual( "s o m e  s p a c e s" );
  });

});

// load jasmine htmlReporter
(function() {
  var env = jasmine.getEnv();
  env.addReporter(new jasmine.HtmlReporter());
  env.execute();
}());