Remove Duplicate from String
Write a function that takes a string as an input, and remove duplicate from the string
by Pranab Dey
HTML
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mocha/3.1.0/mocha.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/3.1.0/mocha.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chai/3.5.0/chai.min.js"></script>
<div style="padding: 10px; color: grey">
<h4>Problem:</h4>
<p>Write a function that takes a string as an input, and remove duplicate from the string</p>
<p><strong>Sample Input:</strong> Learn js dude</p>
<p><strong>Sample Output:</strong> Learnjsdu</p>
</div>
<hr><br><br>
<div id="mocha"></div>
JavaScript
// Please note that you cannot edit HTML/CSS or include any libraries.
// You can use ES2016 (Babel) or ES5 to solve this problem:
function removeDuplicateFromString(string) {
var str = string.split('');
return str.filter(function(el, r, s) {
return s.indexOf(el) === r;
}).join("");
}
// If your solution pass all tests, you should see a green tick for all test cases.
// Don't edit below this line.
mocha.setup("bdd");
chai.should();
describe('Remove Duplicate from String ', function(){
it('Test Case #1 - Learn js dude', function(){
var output = removeDuplicateFromString('Learn js dude');
output.should.equal('Learn jsdu');
});
it('Test Case #2 - Foobar', function(){
var output = removeDuplicateFromString('Foobar');
output.should.equal('Fobar');
});
});
mocha.run();