supasympa
11/12/2014 - 11:41 AM

Simple Javascript and Angular test for developers

Simple Javascript and Angular test for developers

JAVASCRIPT - around 60 mins to complete:

/* code  */

var wordsCollection = [];
var sentence = 'A sentence of words that we\'d like to seperate';
var position = 0;

function splitSentence(s, i){
    var parts;
    parts = [s.substr(0, i), s.substr(i+1)];
    return parts;
};

function findNextWord(s){
    var index = s.indexOf(' ');
	var sentenceParts;

	if(index >=0){
		sentenceParts = splitSentence(s, index); 
		wordsCollection.push(sentenceParts[0]);
		sentence = sentenceParts[1];
		return true;	
	}else{
     wordsCollection.push(sentence);   
    return false;
	}
};


while(findNextWord(sentence)){}

console.log(wordsCollection);

/* end code  */



1) Rewrite the above code to make it more efficient.
2) Convert the code so that you can pass in any string.
3) Write some tests that proves your new code works with the following strings:
	a) "A new  sentence that has multiple    spaces in it 1";
	b) "A new  sentence thathasmultiple    spaces in it 2";
	c) "  A new  sentence thathasmultiple    spaces in it  3 ";
4) Demonstrate how your code is more efficient.
5) Demonstrate how you can use your new code to retrieve a string from a resource at a remote location on internet 	


========================================================================


ANGULAR JS - around 60 mins to complete:

Angular
Imagine you have some HTML:

<!-- snippet -->
<div id="myPage">
<h1>Hy my name is MyName</h1>
<p><!-- add remote text here--></p>
<input type="text" name="name">
<input type="text" name="aboutMeUrl"/>
<button>GO</button>
</div>
<!-- end snippet-->



Write some tested code to do the following:
1) Allow the user to enter a bio on the http://about.me website
2) Retrieve the users bio
3) Render the biography correctly in place of the tag : <!-- add remote text here-->