diff --git a/solutions/64.js b/solutions/64.js index 5e933c3..5a8e7f2 100644 --- a/solutions/64.js +++ b/solutions/64.js @@ -14,7 +14,7 @@ const reverseInput = (string) => { newString += string[i]; }; return newString; -} +}; /** * @param {string} sentence - a sentence @@ -38,6 +38,16 @@ const solution = (sentence) => { return result.join(' '); }; +const solution2 = (actual) => { + let splitArr = actual.split(' '); + for (let i=0; i { + if(/^[a-zA-Z]+$/.test(actual[0]) === true){ actual.sort(); + return actual; + } else { + actual.sort(function (a,b){ + return a-b; + }); + return actual; + } + }; + -const yourSolution = () => { -}; module.exports = { - yourSolution, + solution3, }; diff --git a/test/5.js b/test/5.js index 5bb5cb0..ecd27c0 100644 --- a/test/5.js +++ b/test/5.js @@ -1,6 +1,7 @@ const expect = require('chai').expect; let solution = require('../solutions/5').solution; let solution2 = require('../solutions/5').solution2; +let solution3 = require('../solutions/yourSolution').solution3; describe('sort arrays', () => { // solution tests @@ -47,5 +48,12 @@ describe('sort arrays', () => { const actual = [57]; const expected = [57]; expect(solution2(actual)).eql(expected); - }); + }); + // for solution3 + it.only('solution2 - array should have numbers in ascending order - single', + () => { + const actual = [1, 5, 31, 57, 2, 0]; + const expected = [0, 1, 2, 5, 31, 57]; + expect(solution3(actual)).eql(expected); + }); }); diff --git a/test/64.js b/test/64.js index 3a607a6..cd99039 100644 --- a/test/64.js +++ b/test/64.js @@ -1,6 +1,6 @@ const expect = require('chai').expect; let solution = require('../solutions/64').solution; -// solution = require('./yourSolution').solution; +let solution2 = require('../solutions/64').solution2; describe('reverse word order in a sentence', () => { it('should reverse the word order', () => { @@ -9,4 +9,8 @@ describe('reverse word order in a sentence', () => { it('should return I', () => { expect(solution('I')).eql('I'); }); + it.only('should reverse word order', () => { + expect(solution2('happy goes it')).eql('it goes happy'); + + }); });