Skip to content

Commit

Permalink
Merge pull request #99 from seemcat/mc9
Browse files Browse the repository at this point in the history
Test & Solution for #31.
  • Loading branch information
yjlim5 authored Jun 15, 2017
2 parents 78af455 + f5a0be4 commit 4b177b3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
20 changes: 17 additions & 3 deletions solutions/31.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
// input: ['hi','hello','hola']
// output 'hello'

// Solutions by Colin Xie @ColinX13

// Solution by Colin Xie @ColinX13
// Solution1 by Maricris Bonzo @Seemcat
/**
* @param {string[]} arr - the array of strings
* @return {string} word - the longest word in the array
*/
*/
const solution = (arr) => {
let maxLength = 0;
let word = 0;
Expand All @@ -20,6 +20,20 @@ const solution = (arr) => {
}
return word;
};

const solution1 = (arr) => {
let big = arr[0];
let i = 1;
while(i < arr.length){
if (big.length < arr[i].length){
big = arr[i];
}
i++;
};
return big;
};

module.exports = {
solution,
solution1
};
16 changes: 16 additions & 0 deletions test/31.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const expect = require('chai').expect;
let solution = require('../solutions/31').solution;
let solution1 = require('../solutions/31').solution1;
// solution = require('./yourSolution').solution;

describe('longest string in an array', () => {
Expand All @@ -19,4 +20,19 @@ describe('longest string in an array', () => {
it('the longest string in [just] is just', () => {
expect(solution(['just'])).eql('just');
});
it.only('the longest string in [hi,hello,hola] is hello', () => {
expect(solution1(['hi','hello','hola'])).eql('hello');
})
it.only('the longest string in [is, whether, approximately] is approximately', () => {
expect(solution1(['is','whether','approximately'])).eql('approximately');
})
it.only('the longest string in [wait,see,us] is wait', () => {
expect(solution1(['wait','see','us'])).eql('wait');
})
it.only('the longest string in [shout,basic,lead] is shout', () => {
expect(solution1(['shout','basic','lead'])).eql('shout');
})
it.only('the longest string in [just] is just', () => {
expect(solution1(['just'])).eql('just');
})
});

0 comments on commit 4b177b3

Please sign in to comment.