Skip to content

done #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules/
*~
1 change: 0 additions & 1 deletion ExerciseOne/test-words-utility.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<title>Unit Tests for - the words utility</title>
<link rel="stylesheet" type="text/css" href="../qunit/qunit.css">
<script src="../qunit/qunit.js"></script>
<script src="../qunit/qunit-reporter-junit.js"></script>
<script src="words-utility.js"></script>
<script src="words-utility-tests.js"></script>
</head>
Expand Down
8 changes: 4 additions & 4 deletions ExerciseOne/words-utility-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ QUnit.test( "test if words are counted correctly", function( assert ) {
});

QUnit.test( "find the longest word", function( assert ) {
var wordsUtility = new WordsUtility("ola yeah yoyoyo yoda");
assert.equal(wordsUtility.longestWord(), "yoyoyo");
var wordsUtility = new WordsUtility(theWords);
assert.equal(wordsUtility.longestWord(), "dependencies");
});

QUnit.test( "the average word length of words supplied", function( assert ) {
Expand All @@ -31,8 +31,8 @@ QUnit.test( "no words with the same length return nothing", function( assert ) {
});

QUnit.test( "find the shortest word", function( assert ) {
var wordsUtility = new WordsUtility("ola yeah yoyoyo");
assert.equal(wordsUtility.shortestWord(), "ola");
var wordsUtility = new WordsUtility(theWords);
assert.equal(wordsUtility.shortestWord(), "A");
});

QUnit.jUnitReport = function(report) {
Expand Down
47 changes: 44 additions & 3 deletions ExerciseOne/words-utility.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,48 @@

WordsUtility = function(words){
WordsUtility = function(theWords){

this.countWords = function(){
return words.split(" ").length;
return theWords.split(" ").length;

}


this.longestWord = function(){
var list1 = theWords.split(" ");
var longestWord = " "
for (i=0; i < list1.length; i++){
if (list1[i].length > longestWord.length){
longestWord = list1[i];

}
}
return(longestWord);
}
}


this.averageWordLength = function(){

var list1 = theWords.split(" ");

var list1 = thewords.length;
var totalCharacters = 0;
for(var i = 0; i < theWords; i++)
totalCharacters = totalCharacters + words[i].length();

return (theWords);

}
this.shortestWord =function(){
var list1 = theWords.split(" ");
var shortestWord = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx"
for (i=0; i < list1.length; i++){
if (list1[i].length < shortestWord.length){
shortestWord = list1[i];

}
}
return(shortestWord);


}
};