Skip to content

Commit

Permalink
solutions and test llipio#31
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinX13 committed Jun 5, 2017
1 parent cc60d0d commit 249091b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
19 changes: 19 additions & 0 deletions solutions/31.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// return longest string

// input: ['hi','hello','hola']
// output 'hello'

const solution = (arr) => {
let length = 0;
let word = 0
for(let i = 0; i < arr.length; i++){
if(arr[i].length > length){
length = arr[i].length;
word = arr[i];
}
}
return word;
};
module.exports = {
solution
};
18 changes: 18 additions & 0 deletions test/31.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const expect = require('chai').expect;
let solution = require('../solutions/31').solution;
// solution = require('./yourSolution').solution;

describe('longest string in an array', () => {
it('the longest string in [hi,hello,hola] is hello', () => {
expect(solution(['hi','hello','hola'])).eql('hello');
})
it('the longest string in [is, whether, approximately] is approximately', () => {
expect(solution(['is','whether','approximately'])).eql('approximately');
})
it('the longest string in [wait,see,us] is wait', () => {
expect(solution(['wait','see','us'])).eql('wait');
})
it('the longest string in [shout,basic,lead]', () => {
expect(solution(['shout','basic','lead'])).eql('shout');
})
});

0 comments on commit 249091b

Please sign in to comment.