forked from rmurphey/js-assessment
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aac8e18
commit e8e2c44
Showing
4 changed files
with
68 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ | |
"numbersAnswers", | ||
"objectsAnswers", | ||
"recursionAnswers", | ||
"regexAnswers" | ||
"regexAnswers", | ||
"stringsAnswers" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
exports = (typeof window === 'undefined') ? global : window; | ||
|
||
exports.stringsAnswers = { | ||
reduceString: function(str, amount) { | ||
|
||
}, | ||
wordWrap: function(str, cols) { | ||
|
||
}, | ||
reverseString: function(str) { | ||
|
||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
if ( typeof window === 'undefined' ) { | ||
require('../../app/strings'); | ||
var expect = require('chai').expect; | ||
} | ||
|
||
describe('strings', function() { | ||
it('you should be able to reduce duplicate characters to a desired minimum', function() { | ||
expect(stringsAnswers.reduceString('aaaabbbb', 2)).to.eql('aabb'); | ||
expect(stringsAnswers.reduceString('xaaabbbb', 2)).to.eql('xaabb'); | ||
expect(stringsAnswers.reduceString('aaaabbbb', 1)).to.eql('ab'); | ||
expect(stringsAnswers.reduceString('aaxxxaabbbb', 2)).to.eql('aaxxaabb'); | ||
}); | ||
|
||
it('you should be able to wrap lines at a given number of columns, without breaking words', function() { | ||
var wrapCol = 5; | ||
var inputStrings = [ | ||
'abcdef abcde abc def', | ||
'abc abc abc', | ||
'a b c def' | ||
]; | ||
var outputStrings = [ | ||
'abcdef\nabcde\nabc\ndef', | ||
'abc\nabc\nabc', | ||
'a b c\ndef' | ||
]; | ||
var formattedStr; | ||
|
||
inputStrings.forEach(function(str, index) { | ||
formattedStr = stringsAnswers.wordWrap(str, wrapCol); | ||
expect(formattedStr).to.eql(outputStrings[index]); | ||
}); | ||
}); | ||
|
||
it('you should be able to reverse a string', function() { | ||
var inputStrings = [ | ||
'abc', | ||
'i am a string of characters', | ||
'A man, a plan, a canal: Panama' | ||
]; | ||
var outputStrings = [ | ||
'cba', | ||
'sretcarahc fo gnirts a ma i', | ||
'amanaP :lanac a ,nalp a ,nam A' | ||
]; | ||
|
||
inputStrings.forEach(function(str, index) { | ||
var result = stringsAnswers.reverseString(str); | ||
expect(result).to.eql(outputStrings[index]); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters