From 290e7f1da41641c3d028d0ef19669be35144a33a Mon Sep 17 00:00:00 2001 From: Cody Loyd Date: Mon, 20 Nov 2017 13:51:01 -0600 Subject: [PATCH] remove class based exercises --- book_titles/README.md | 3 -- book_titles/bookTitles.js | 8 ---- book_titles/bookTitles.spec.js | 64 ------------------------- helloWorld/helloWorld.js | 4 +- leapYears/leapYears.js | 7 ++- leapYears/leapYears.spec.js | 10 ++-- removeFromArray/removeFromArray.js | 12 ++++- removeFromArray/removeFromArray.spec.js | 10 ++-- repeatString/README.md | 2 +- repeatString/repeatString.js | 9 +++- repeatString/repeatString.spec.js | 8 ++-- reverseString/reverseString.js | 6 +-- reverseString/reverseString.spec.js | 6 +-- sumAll/sumAll.js | 19 +++++++- sumAll/sumAll.spec.js | 10 ++-- timer/README.md | 11 ----- timer/timer.js | 7 --- timer/timer.spec.js | 35 -------------- 18 files changed, 67 insertions(+), 164 deletions(-) delete mode 100644 book_titles/README.md delete mode 100644 book_titles/bookTitles.js delete mode 100644 book_titles/bookTitles.spec.js delete mode 100644 timer/README.md delete mode 100644 timer/timer.js delete mode 100644 timer/timer.spec.js diff --git a/book_titles/README.md b/book_titles/README.md deleted file mode 100644 index acf79cf..0000000 --- a/book_titles/README.md +++ /dev/null @@ -1,3 +0,0 @@ -The goal of this exercise is to introduce you to the concept of objects and classes. These are fundamental building blocks for OOP (Object Oriented Programming). You shouldn't need to write a ton of new code, in fact you can re-use your solution from the Simon Says exercise! - -The key here will be rewriting certain bits of it to work within the class given to you. \ No newline at end of file diff --git a/book_titles/bookTitles.js b/book_titles/bookTitles.js deleted file mode 100644 index e546db0..0000000 --- a/book_titles/bookTitles.js +++ /dev/null @@ -1,8 +0,0 @@ -class bookTitle { - -} - -module.exports = { - bookTitle -} - diff --git a/book_titles/bookTitles.spec.js b/book_titles/bookTitles.spec.js deleted file mode 100644 index 3a0e8ad..0000000 --- a/book_titles/bookTitles.spec.js +++ /dev/null @@ -1,64 +0,0 @@ -var bookTitles = require ('./bookTitles.js'); - -describe('bookTitle', function() { - - var book; // note the scope here, if you declare this inside beforeEach then the scope won't allow it to access the other specs - - beforeEach(function() { - book = new bookTitles.bookTitle(); // creates a new book instance before each test is run - }); - - describe('title', function() { - - it('should capitalize the first letter', function() { - book.title = 'inferno'; - expect(book.title).toEqual('Inferno'); - }); - - it('should capitalize every word', function() { - book.title = 'stuart little'; - expect(book.title).toEqual('Stuart Little'); - }); - - describe('should capitalize every word except...', function() { - describe('articles', function() { - it('does not capitalize "the"', function() { - book.title = 'alexander the great'; - expect(book.title).toEqual('Alexander the Great'); - }); - - it('does not capitalize "a"', function() { - book.title = 'to kill a mockingbird'; - expect(book.title).toEqual('To Kill a Mockingbird'); - }); - - it('does not capitalize "an"', function() { - book.title = 'to eat an apple a day'; - expect(book.title).toEqual('To Eat an Apple a Day'); - }); - }); - - it('conjunctions', function() { - book.title = 'war and peace'; - expect(book.title).toEqual('War and Peace'); - }); - - it('prepositions', function() { - book.title = 'love in the time of cholera'; - expect(book.title).toEqual('Love in the Time of Cholera'); - }); - }); - - describe('should always capitalize...', function() { - it('I', function() { - book.title = 'what i wish i knew when i was 20'; - expect(book.title).toEqual('What I Wish I Knew When I Was 20'); - }); - - it('the first word', function() { - book.title = 'the man in the iron mask'; - expect(book.title).toEqual('The Man in the Iron Mask'); - }); - }); - }); -}); \ No newline at end of file diff --git a/helloWorld/helloWorld.js b/helloWorld/helloWorld.js index cf8cd75..9029bef 100644 --- a/helloWorld/helloWorld.js +++ b/helloWorld/helloWorld.js @@ -1,5 +1,5 @@ var helloWorld = function() { - return '' + return 'Hello, World!' } -module.exports = helloWorld \ No newline at end of file +module.exports = helloWorld diff --git a/leapYears/leapYears.js b/leapYears/leapYears.js index 7884b78..9b55920 100644 --- a/leapYears/leapYears.js +++ b/leapYears/leapYears.js @@ -1,5 +1,8 @@ -var leapYears = function() { - +var leapYears = function(year) { + if (year % 4 !== 0 || (year % 100 == 0 && year % 400 != 0)) { + return false + } + return true } module.exports = leapYears diff --git a/leapYears/leapYears.spec.js b/leapYears/leapYears.spec.js index b58dadb..0af23c3 100644 --- a/leapYears/leapYears.spec.js +++ b/leapYears/leapYears.spec.js @@ -4,19 +4,19 @@ describe('leapYears', function() { it('works with non century years', function() { expect(leapYears(1996)).toEqual(true); }); - xit('works with non century years', function() { + it('works with non century years', function() { expect(leapYears(1997)).toEqual(false); }); - xit('works with ridiculously futuristic non century years', function() { + it('works with ridiculously futuristic non century years', function() { expect(leapYears(34992)).toEqual(true); }); - xit('works with century years', function() { + it('works with century years', function() { expect(leapYears(1900)).toEqual(false); }); - xit('works with century years', function() { + it('works with century years', function() { expect(leapYears(1600)).toEqual(true); }); - xit('works with century years', function() { + it('works with century years', function() { expect(leapYears(700)).toEqual(false); }); }); diff --git a/removeFromArray/removeFromArray.js b/removeFromArray/removeFromArray.js index d36b8b1..ccb4343 100644 --- a/removeFromArray/removeFromArray.js +++ b/removeFromArray/removeFromArray.js @@ -1,5 +1,13 @@ -var removeFromArray = function() { - +var removeFromArray = function(array) { + elementsToRemove = [...arguments] + elementsToRemove.splice(0,1) + elementsToRemove.forEach(element => { + let index = array.indexOf(element) + if (index > -1) { + array.splice(index, 1) + } + }) + return array } module.exports = removeFromArray diff --git a/removeFromArray/removeFromArray.spec.js b/removeFromArray/removeFromArray.spec.js index ff94e9a..9b5d9f9 100644 --- a/removeFromArray/removeFromArray.spec.js +++ b/removeFromArray/removeFromArray.spec.js @@ -4,19 +4,19 @@ describe('removeFromArray', function() { it('removes a single value', function() { expect(removeFromArray([1, 2, 3, 4], 3)).toEqual([1, 2, 4]); }); - xit('removes multiple values', function() { + it('removes multiple values', function() { expect(removeFromArray([1, 2, 3, 4], 3, 2)).toEqual([1, 4]); }); - xit('ignores non present values', function() { + it('ignores non present values', function() { expect(removeFromArray([1, 2, 3, 4], 7, "tacos")).toEqual([1, 2, 3, 4]); }); - xit('ignores non present values, but still works', function() { + it('ignores non present values, but still works', function() { expect(removeFromArray([1, 2, 3, 4], 7, 2)).toEqual([1, 3, 4]); }); - xit('can remove all values', function() { + it('can remove all values', function() { expect(removeFromArray([1, 2, 3, 4], 1, 2, 3, 4)).toEqual([]); }); - xit('works with strings', function() { + it('works with strings', function() { expect(removeFromArray(["hey", 2, 3, "ho"], "hey", 3)).toEqual([2, "ho"]); }); }); diff --git a/repeatString/README.md b/repeatString/README.md index cefaa89..b80b6c6 100644 --- a/repeatString/README.md +++ b/repeatString/README.md @@ -1,4 +1,4 @@ -# Exercise 02 - repeatString +# Exercis 02 - repeatString Write a function that simply repeats the string a given number of times: diff --git a/repeatString/repeatString.js b/repeatString/repeatString.js index 49dfa90..e69f9d5 100644 --- a/repeatString/repeatString.js +++ b/repeatString/repeatString.js @@ -1,5 +1,10 @@ -var repeatString = function() { - +var repeatString = function(string, num) { + if (num < 0) return 'ERROR' + let returnValue = '' + for(let i = 0; i < num; i++) { + returnValue = returnValue + string + } + return returnValue } module.exports = repeatString diff --git a/repeatString/repeatString.spec.js b/repeatString/repeatString.spec.js index 3a33a3f..1b695d4 100644 --- a/repeatString/repeatString.spec.js +++ b/repeatString/repeatString.spec.js @@ -4,16 +4,16 @@ describe('repeatString', function() { it('repeats the string', function() { expect(repeatString('hey', 3)).toEqual('heyheyhey'); }); - xit('repeats the string many times', function() { + it('repeats the string many times', function() { expect(repeatString('hey', 10)).toEqual('heyheyheyheyheyheyheyheyheyhey'); }); - xit('repeats the string 1 times', function() { + it('repeats the string 1 times', function() { expect(repeatString('hey', 1)).toEqual('hey'); }); - xit('repeats the string 0 times', function() { + it('repeats the string 0 times', function() { expect(repeatString('hey', 0)).toEqual(''); }); - xit('returns ERROR with negative numbers', function() { + it('returns ERROR with negative numbers', function() { expect(repeatString('hey', -1)).toEqual('ERROR'); }); }); diff --git a/reverseString/reverseString.js b/reverseString/reverseString.js index bca22be..8c074fc 100644 --- a/reverseString/reverseString.js +++ b/reverseString/reverseString.js @@ -1,5 +1,5 @@ -var reverseString = function() { - +var reverseString = function(string) { + return string.split('').reverse().join('') } -module.exports = reverseString \ No newline at end of file +module.exports = reverseString diff --git a/reverseString/reverseString.spec.js b/reverseString/reverseString.spec.js index 18887f7..6f157e4 100644 --- a/reverseString/reverseString.spec.js +++ b/reverseString/reverseString.spec.js @@ -5,11 +5,11 @@ describe('Hello World', function() { expect(reverseString('hello')).toEqual('olleh'); }); - xit('reverses multiple words', function() { + it('reverses multiple words', function() { expect(reverseString('hello there')).toEqual('ereht olleh') }) - xit('works with numbers and punctuation', function() { + it('works with numbers and punctuation', function() { expect(reverseString('123! abc!')).toEqual('!cba !321') }) -}); \ No newline at end of file +}); diff --git a/sumAll/sumAll.js b/sumAll/sumAll.js index 863a79d..01d0116 100644 --- a/sumAll/sumAll.js +++ b/sumAll/sumAll.js @@ -1,5 +1,20 @@ -var sumAll = function() { - +var sumAll = function(a, b) { + if (a > b) { + let temp = a + a = b + b = temp + } + if ( + a < 0 || b < 0 || + typeof a != 'number' || typeof b != 'number' + ) { + return 'ERROR' + } + let sum = 0 + for(let i = a; i < b + 1; i++) { + sum += i + } + return sum } module.exports = sumAll diff --git a/sumAll/sumAll.spec.js b/sumAll/sumAll.spec.js index 7f48e7a..59631fa 100644 --- a/sumAll/sumAll.spec.js +++ b/sumAll/sumAll.spec.js @@ -4,19 +4,19 @@ describe('sumAll', function() { it('sums numbers within the range', function() { expect(sumAll(1, 4)).toEqual(10); }); - xit('works with large numbers', function() { + it('works with large numbers', function() { expect(sumAll(1, 4000)).toEqual(8002000); }); - xit('works with larger number first', function() { + it('works with larger number first', function() { expect(sumAll(123, 1)).toEqual(7626); }); - xit('returns ERROR with negative numbers', function() { + it('returns ERROR with negative numbers', function() { expect(sumAll(-10, 4)).toEqual('ERROR'); }); - xit('returns ERROR with non-number parameters', function() { + it('returns ERROR with non-number parameters', function() { expect(sumAll(10, "90")).toEqual('ERROR'); }); - xit('returns ERROR with non-number parameters', function() { + it('returns ERROR with non-number parameters', function() { expect(sumAll(10, [90, 1])).toEqual('ERROR'); }); }); diff --git a/timer/README.md b/timer/README.md deleted file mode 100644 index 97ae612..0000000 --- a/timer/README.md +++ /dev/null @@ -1,11 +0,0 @@ -The goal of this exercise is for you to create a timer. The timer will operate with the following format: - -00:00:00 - -You will be given an object with the value of seconds already added. Your job is to use the class to add a string containing the timer result to this original object. - -Example: - -12 seconds given - -00:00:12 should be the output \ No newline at end of file diff --git a/timer/timer.js b/timer/timer.js deleted file mode 100644 index 3cd09b8..0000000 --- a/timer/timer.js +++ /dev/null @@ -1,7 +0,0 @@ -class timeFormat { - -} - -module.exports = { - timeFormat -} diff --git a/timer/timer.spec.js b/timer/timer.spec.js deleted file mode 100644 index d6ce0e2..0000000 --- a/timer/timer.spec.js +++ /dev/null @@ -1,35 +0,0 @@ -var Timer = require ('./timer.js'); - -describe('Timer', function() { - var timer; // undefined, here for scope purposes - - beforeEach(function () { - timer = new Timer.timeFormat(); - }); - - it('should initialize to 0 seconds', function() { - expect(timer.seconds).toEqual(0); // makes sure timer starts with 0 seconds - }); - - describe('time_string', function() { - it('should display 0 seconds as 00:00:00', function() { - timer.seconds = 0; - expect(timer.time_string()).toEqual("00:00:00"); - }); - - it('should display 12 seconds as 00:00:12', function() { - timer.seconds = 12; - expect(timer.time_string()).toEqual("00:00:12"); - }); - - it('should display 66 seconds as 00:01:06', function() { - timer.seconds = 66; - expect(timer.time_string()).toEqual("00:01:06"); - }); - - it('should display 4000 seconds as 01:06:40', function() { - timer.seconds = 4000; - expect(timer.time_string()).toEqual("01:06:40"); - }); - }); -}); \ No newline at end of file