From 9edc919b789332d6c0fff9e4e0a8512c91fb73c8 Mon Sep 17 00:00:00 2001 From: Monica Williams Date: Tue, 4 Apr 2017 14:48:50 -0700 Subject: [PATCH 01/13] check to make sure that input is a string is working --- exercism/pangram/pangram.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 exercism/pangram/pangram.js diff --git a/exercism/pangram/pangram.js b/exercism/pangram/pangram.js new file mode 100644 index 0000000..408cd56 --- /dev/null +++ b/exercism/pangram/pangram.js @@ -0,0 +1,27 @@ +function Pangram( str ) { + this.str = str + this.asciiLookup = { + a: 0, b: 0, c: 0, d: 0, e: 0, f: 0, g: 0, h: 0, i: 0, j: 0, k: 0, l: 0, m: 0, + n: 0, o: 0, p: 0, q: 0, r: 0, s: 0, t: 0, u: 0, v: 0, w: 0, x: 0, y: 0, z: 0 + } +} + +Pangram.prototype.isPangram = function() { + var stringToCheckPanagramStatusOn = this.str + + if ( stringToCheckPanagramStatusOn.length < 1 || typeof stringToCheckPanagramStatusOn !== 'string' ) { + return false + } + //if the string has no length/isEmpty, don't do anything + //if the input !string, don't do anything + + //iterate over the string + //at each index, lookup string[i] in the asciiLookup and set its value to 1 + //if there are any values that are still 0 by the time the iteration is done, function should return false +} + +module.exports = Pangram + +var thing = new Pangram( 1 ) + +console.log(thing.isPangram()) From 4cc6a84fee3dc77ae89cf2b10817a59d165fbb6f Mon Sep 17 00:00:00 2001 From: Monica Williams Date: Tue, 4 Apr 2017 16:16:53 -0700 Subject: [PATCH 02/13] some tests passing, need to work on handling uppercase and symbols --- exercism/pangram/pangram.js | 30 +++++++++++++++++++----------- exercism/pangram/pangram.spec.js | 8 ++++---- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/exercism/pangram/pangram.js b/exercism/pangram/pangram.js index 408cd56..8177251 100644 --- a/exercism/pangram/pangram.js +++ b/exercism/pangram/pangram.js @@ -1,5 +1,5 @@ function Pangram( str ) { - this.str = str + this.str = str, this.asciiLookup = { a: 0, b: 0, c: 0, d: 0, e: 0, f: 0, g: 0, h: 0, i: 0, j: 0, k: 0, l: 0, m: 0, n: 0, o: 0, p: 0, q: 0, r: 0, s: 0, t: 0, u: 0, v: 0, w: 0, x: 0, y: 0, z: 0 @@ -7,21 +7,29 @@ function Pangram( str ) { } Pangram.prototype.isPangram = function() { - var stringToCheckPanagramStatusOn = this.str - if ( stringToCheckPanagramStatusOn.length < 1 || typeof stringToCheckPanagramStatusOn !== 'string' ) { + if ( this.str.length < 1 || typeof this.str !== 'string' ) { return false + } else { + for ( var i = 0; i < this.str.length; i++ ) { + this.asciiLookup[this.str[i]] = 1 + } + for (var prop in this.asciiLookup) { + if ( this.asciiLookup[prop] === 1 ) { + return true + } else { + return false + } + } } - //if the string has no length/isEmpty, don't do anything - //if the input !string, don't do anything - - //iterate over the string - //at each index, lookup string[i] in the asciiLookup and set its value to 1 - //if there are any values that are still 0 by the time the iteration is done, function should return false } module.exports = Pangram -var thing = new Pangram( 1 ) +// var thing = new Pangram( 'the quick brown fox jumps over the lazy dog' ) +// +// console.log(thing.isPangram()) +// console.log( thing.asciiLookup) -console.log(thing.isPangram()) +//turn characters to upper case +//remove symbols diff --git a/exercism/pangram/pangram.spec.js b/exercism/pangram/pangram.spec.js index d7feee3..da55c03 100644 --- a/exercism/pangram/pangram.spec.js +++ b/exercism/pangram/pangram.spec.js @@ -2,22 +2,22 @@ var Pangram = require('./pangram'); describe('Pangram()', function() { - it('empty sentence', function() { + xit('empty sentence', function() { var pangram = new Pangram(''); expect(pangram.isPangram()).toBe(false); }); - xit('pangram with only lower case', function() { + it('pangram with only lower case', function() { var pangram = new Pangram("the quick brown fox jumps over the lazy dog"); expect(pangram.isPangram()).toBe(true); }); - xit("missing character 'x'", function() { + it("missing character 'x'", function() { var pangram = new Pangram("a quick movement of the enemy will jeopardize five gunboats"); expect(pangram.isPangram()).toBe(false); }); - xit("another missing character 'x'", function() { + it("another missing character 'x'", function() { var pangram = new Pangram("the quick brown fish jumps over the lazy dog"); expect(pangram.isPangram()).toBe(false); }); From 5ba78cd1e00aca57658d555ba20952802597a94b Mon Sep 17 00:00:00 2001 From: Monica Williams Date: Tue, 4 Apr 2017 21:29:58 -0700 Subject: [PATCH 03/13] all tests passed, not optimized yet --- exercism/pangram/pangram.js | 16 ++++------------ exercism/pangram/pangram.spec.js | 13 +++++++------ 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/exercism/pangram/pangram.js b/exercism/pangram/pangram.js index 8177251..246b083 100644 --- a/exercism/pangram/pangram.js +++ b/exercism/pangram/pangram.js @@ -11,25 +11,17 @@ Pangram.prototype.isPangram = function() { if ( this.str.length < 1 || typeof this.str !== 'string' ) { return false } else { + this.str = this.str.toLowerCase() for ( var i = 0; i < this.str.length; i++ ) { this.asciiLookup[this.str[i]] = 1 } - for (var prop in this.asciiLookup) { - if ( this.asciiLookup[prop] === 1 ) { - return true - } else { + for ( var prop in this.asciiLookup ) { + if ( this.asciiLookup[prop] === 0 ) { return false } } + return true } } module.exports = Pangram - -// var thing = new Pangram( 'the quick brown fox jumps over the lazy dog' ) -// -// console.log(thing.isPangram()) -// console.log( thing.asciiLookup) - -//turn characters to upper case -//remove symbols diff --git a/exercism/pangram/pangram.spec.js b/exercism/pangram/pangram.spec.js index da55c03..828f9eb 100644 --- a/exercism/pangram/pangram.spec.js +++ b/exercism/pangram/pangram.spec.js @@ -2,7 +2,7 @@ var Pangram = require('./pangram'); describe('Pangram()', function() { - xit('empty sentence', function() { + it('empty sentence', function() { var pangram = new Pangram(''); expect(pangram.isPangram()).toBe(false); }); @@ -22,27 +22,28 @@ describe('Pangram()', function() { expect(pangram.isPangram()).toBe(false); }); - xit("pangram with underscores", function() { + it("pangram with underscores", function() { var pangram = new Pangram("the_quick_brown_fox_jumps_over_the_lazy_dog"); expect(pangram.isPangram()).toBe(true); }); - xit("pangram with numbers", function() { + it("pangram with numbers", function() { var pangram = new Pangram("the 1 quick brown fox jumps over the 2 lazy dogs"); expect(pangram.isPangram()).toBe(true); }); - xit('missing letters replaced by numbers', function() { + it('missing letters replaced by numbers', function() { var pangram = new Pangram("7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog"); + console.log() expect(pangram.isPangram()).toBe(false); }); - xit('pangram with mixed case and punctuation', function() { + it('pangram with mixed case and punctuation', function() { var pangram = new Pangram("\"Five quacking Zephyrs jolt my wax bed.\""); expect(pangram.isPangram()).toBe(true); }); - xit('pangram with non-ascii characters', function() { + it('pangram with non-ascii characters', function() { var pangram = new Pangram("Victor jagt zwölf Boxkämpfer quer über den großen Sylter Deich."); expect(pangram.isPangram()).toBe(true); }); From 615df3cf1d005537d4ff0532ef852a93c0800710 Mon Sep 17 00:00:00 2001 From: Monica Williams Date: Tue, 4 Apr 2017 14:48:50 -0700 Subject: [PATCH 04/13] check to make sure that input is a string is working --- exercism/pangram/pangram.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 exercism/pangram/pangram.js diff --git a/exercism/pangram/pangram.js b/exercism/pangram/pangram.js new file mode 100644 index 0000000..408cd56 --- /dev/null +++ b/exercism/pangram/pangram.js @@ -0,0 +1,27 @@ +function Pangram( str ) { + this.str = str + this.asciiLookup = { + a: 0, b: 0, c: 0, d: 0, e: 0, f: 0, g: 0, h: 0, i: 0, j: 0, k: 0, l: 0, m: 0, + n: 0, o: 0, p: 0, q: 0, r: 0, s: 0, t: 0, u: 0, v: 0, w: 0, x: 0, y: 0, z: 0 + } +} + +Pangram.prototype.isPangram = function() { + var stringToCheckPanagramStatusOn = this.str + + if ( stringToCheckPanagramStatusOn.length < 1 || typeof stringToCheckPanagramStatusOn !== 'string' ) { + return false + } + //if the string has no length/isEmpty, don't do anything + //if the input !string, don't do anything + + //iterate over the string + //at each index, lookup string[i] in the asciiLookup and set its value to 1 + //if there are any values that are still 0 by the time the iteration is done, function should return false +} + +module.exports = Pangram + +var thing = new Pangram( 1 ) + +console.log(thing.isPangram()) From 816b736e74217ceafbbd92b720b4885db34a2eed Mon Sep 17 00:00:00 2001 From: Monica Williams Date: Tue, 4 Apr 2017 16:16:53 -0700 Subject: [PATCH 05/13] some tests passing, need to work on handling uppercase and symbols --- exercism/pangram/pangram.js | 30 +++++++++++++++++++----------- exercism/pangram/pangram.spec.js | 8 ++++---- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/exercism/pangram/pangram.js b/exercism/pangram/pangram.js index 408cd56..8177251 100644 --- a/exercism/pangram/pangram.js +++ b/exercism/pangram/pangram.js @@ -1,5 +1,5 @@ function Pangram( str ) { - this.str = str + this.str = str, this.asciiLookup = { a: 0, b: 0, c: 0, d: 0, e: 0, f: 0, g: 0, h: 0, i: 0, j: 0, k: 0, l: 0, m: 0, n: 0, o: 0, p: 0, q: 0, r: 0, s: 0, t: 0, u: 0, v: 0, w: 0, x: 0, y: 0, z: 0 @@ -7,21 +7,29 @@ function Pangram( str ) { } Pangram.prototype.isPangram = function() { - var stringToCheckPanagramStatusOn = this.str - if ( stringToCheckPanagramStatusOn.length < 1 || typeof stringToCheckPanagramStatusOn !== 'string' ) { + if ( this.str.length < 1 || typeof this.str !== 'string' ) { return false + } else { + for ( var i = 0; i < this.str.length; i++ ) { + this.asciiLookup[this.str[i]] = 1 + } + for (var prop in this.asciiLookup) { + if ( this.asciiLookup[prop] === 1 ) { + return true + } else { + return false + } + } } - //if the string has no length/isEmpty, don't do anything - //if the input !string, don't do anything - - //iterate over the string - //at each index, lookup string[i] in the asciiLookup and set its value to 1 - //if there are any values that are still 0 by the time the iteration is done, function should return false } module.exports = Pangram -var thing = new Pangram( 1 ) +// var thing = new Pangram( 'the quick brown fox jumps over the lazy dog' ) +// +// console.log(thing.isPangram()) +// console.log( thing.asciiLookup) -console.log(thing.isPangram()) +//turn characters to upper case +//remove symbols diff --git a/exercism/pangram/pangram.spec.js b/exercism/pangram/pangram.spec.js index d7feee3..da55c03 100644 --- a/exercism/pangram/pangram.spec.js +++ b/exercism/pangram/pangram.spec.js @@ -2,22 +2,22 @@ var Pangram = require('./pangram'); describe('Pangram()', function() { - it('empty sentence', function() { + xit('empty sentence', function() { var pangram = new Pangram(''); expect(pangram.isPangram()).toBe(false); }); - xit('pangram with only lower case', function() { + it('pangram with only lower case', function() { var pangram = new Pangram("the quick brown fox jumps over the lazy dog"); expect(pangram.isPangram()).toBe(true); }); - xit("missing character 'x'", function() { + it("missing character 'x'", function() { var pangram = new Pangram("a quick movement of the enemy will jeopardize five gunboats"); expect(pangram.isPangram()).toBe(false); }); - xit("another missing character 'x'", function() { + it("another missing character 'x'", function() { var pangram = new Pangram("the quick brown fish jumps over the lazy dog"); expect(pangram.isPangram()).toBe(false); }); From 826de71b5f8a09d80d548d5f772883dfce98d38e Mon Sep 17 00:00:00 2001 From: Monica Williams Date: Tue, 4 Apr 2017 21:29:58 -0700 Subject: [PATCH 06/13] all tests passed, not optimized yet --- exercism/pangram/pangram.js | 16 ++++------------ exercism/pangram/pangram.spec.js | 13 +++++++------ 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/exercism/pangram/pangram.js b/exercism/pangram/pangram.js index 8177251..246b083 100644 --- a/exercism/pangram/pangram.js +++ b/exercism/pangram/pangram.js @@ -11,25 +11,17 @@ Pangram.prototype.isPangram = function() { if ( this.str.length < 1 || typeof this.str !== 'string' ) { return false } else { + this.str = this.str.toLowerCase() for ( var i = 0; i < this.str.length; i++ ) { this.asciiLookup[this.str[i]] = 1 } - for (var prop in this.asciiLookup) { - if ( this.asciiLookup[prop] === 1 ) { - return true - } else { + for ( var prop in this.asciiLookup ) { + if ( this.asciiLookup[prop] === 0 ) { return false } } + return true } } module.exports = Pangram - -// var thing = new Pangram( 'the quick brown fox jumps over the lazy dog' ) -// -// console.log(thing.isPangram()) -// console.log( thing.asciiLookup) - -//turn characters to upper case -//remove symbols diff --git a/exercism/pangram/pangram.spec.js b/exercism/pangram/pangram.spec.js index da55c03..828f9eb 100644 --- a/exercism/pangram/pangram.spec.js +++ b/exercism/pangram/pangram.spec.js @@ -2,7 +2,7 @@ var Pangram = require('./pangram'); describe('Pangram()', function() { - xit('empty sentence', function() { + it('empty sentence', function() { var pangram = new Pangram(''); expect(pangram.isPangram()).toBe(false); }); @@ -22,27 +22,28 @@ describe('Pangram()', function() { expect(pangram.isPangram()).toBe(false); }); - xit("pangram with underscores", function() { + it("pangram with underscores", function() { var pangram = new Pangram("the_quick_brown_fox_jumps_over_the_lazy_dog"); expect(pangram.isPangram()).toBe(true); }); - xit("pangram with numbers", function() { + it("pangram with numbers", function() { var pangram = new Pangram("the 1 quick brown fox jumps over the 2 lazy dogs"); expect(pangram.isPangram()).toBe(true); }); - xit('missing letters replaced by numbers', function() { + it('missing letters replaced by numbers', function() { var pangram = new Pangram("7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog"); + console.log() expect(pangram.isPangram()).toBe(false); }); - xit('pangram with mixed case and punctuation', function() { + it('pangram with mixed case and punctuation', function() { var pangram = new Pangram("\"Five quacking Zephyrs jolt my wax bed.\""); expect(pangram.isPangram()).toBe(true); }); - xit('pangram with non-ascii characters', function() { + it('pangram with non-ascii characters', function() { var pangram = new Pangram("Victor jagt zwölf Boxkämpfer quer über den großen Sylter Deich."); expect(pangram.isPangram()).toBe(true); }); From 48123bdcc20f7bf35046a8b58c06015a71697c98 Mon Sep 17 00:00:00 2001 From: sashajustice Date: Mon, 3 Apr 2017 18:08:07 -0700 Subject: [PATCH 07/13] starts binary search, punit and frankie told us what it meant --- exercism/binary-search/binary-search.js | 35 +++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 exercism/binary-search/binary-search.js diff --git a/exercism/binary-search/binary-search.js b/exercism/binary-search/binary-search.js new file mode 100644 index 0000000..772ffbb --- /dev/null +++ b/exercism/binary-search/binary-search.js @@ -0,0 +1,35 @@ +function BinarySearch( arr ) { +//an object taht has a state and the reason it can change is because it has some +//data it's holding onto and some functions that can act on that data. +//that means there's a state change + this.arr = arr +} + +BinarySearch.prototype.indexOf = function( value ) { + //check if this.arr is sorted + // + + // on the prototoype of bin search we're gonna have a method called index of + +} + + java + + var checkIfArrayIsSorted = function(arr) { + for(var i = 0; i < arr.length; i ++) { + if (arr[i] < arr[i+1]) { + return true; + } else { + return false; + } + } + } + +c++ + + + for(var i = 0; i < thing.length; i++) { + if (thing[i] > thing[i+1]) { + console.log('false'); + } + } From 7228c25595f229a4968abba891ff0e944faaebf6 Mon Sep 17 00:00:00 2001 From: sashajustice Date: Wed, 5 Apr 2017 13:44:40 -0700 Subject: [PATCH 08/13] outline for anagram --- exercism/anagram/anagram.js | 38 +++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 exercism/anagram/anagram.js diff --git a/exercism/anagram/anagram.js b/exercism/anagram/anagram.js new file mode 100644 index 0000000..5f0e441 --- /dev/null +++ b/exercism/anagram/anagram.js @@ -0,0 +1,38 @@ +function Anagram( str ) { + this.str = str, + this.letterHash = {} +} + +Anagram.prototype.matches = function( array ) { + // loop through all chars in str and mark # of time each letter apears + let foundAnagrams = [] + this.hashLetterCount() + console.log(this.letterHash); + console.log('the array we passed in:', array); + // loop through all of the words we are checcking to see if they + // are anagrams of this.str + for( let word in array ) { + if( this.isAnagram( word ) ){ + foundAnagrams.push(word) + } + } + + return foundAnagrams +} + +Anagram.prototype.hashLetterCount = function() { + for( let letter of this.str ){ + if( this.letterHash[letter] === undefined ) { + this.letterHash[letter] = 1 + } else { + this.letterHash[letter]++ + } + } +} + +Anagram.prototype.isAnagram = function( word ) { + +} + +let myAnagram = new Anagram( 'hello' ) +console.log( myAnagram.matches( ['elloh'] ) ); From 001b3d8666143e56a1053d028315e97dd57484f9 Mon Sep 17 00:00:00 2001 From: Monica Williams Date: Wed, 5 Apr 2017 15:55:40 -0700 Subject: [PATCH 09/13] changing branches --- exercism/anagram/anagram.js | 47 ++++++++++++++++++++++++++------ exercism/anagram/anagram.spec.js | 18 ++++++------ 2 files changed, 47 insertions(+), 18 deletions(-) diff --git a/exercism/anagram/anagram.js b/exercism/anagram/anagram.js index 5f0e441..8c38e4b 100644 --- a/exercism/anagram/anagram.js +++ b/exercism/anagram/anagram.js @@ -1,19 +1,22 @@ function Anagram( str ) { - this.str = str, + this.str = str.toLowerCase(), this.letterHash = {} } -Anagram.prototype.matches = function( array ) { +Anagram.prototype.matches = function( ...input ) { // loop through all chars in str and mark # of time each letter apears let foundAnagrams = [] this.hashLetterCount() - console.log(this.letterHash); - console.log('the array we passed in:', array); + // loop through all of the words we are checcking to see if they // are anagrams of this.str - for( let word in array ) { - if( this.isAnagram( word ) ){ - foundAnagrams.push(word) + if ( input[0] instanceof Array ) { + + for( let word of input ) { + console.log('word', word) + if( this.isAnagram( word )) { + foundAnagrams.push(word) + } } } @@ -31,8 +34,34 @@ Anagram.prototype.hashLetterCount = function() { } Anagram.prototype.isAnagram = function( word ) { - + word = word.toLowerCase() + if ( word === this.str ) { + return false + } + if ( word.length !== this.str.length ) { + return false + } + for( let letter of word ) { + console.log('word', word) + if( this.letterHash[letter] === undefined ) { + return false + } else { + this.letterHash[letter]-- + } + } + for( let letter in this.letterHash ) { + if ( this.letterHash[letter] > 0 ) { + return false + } + } + return true + //loop through letterHash. + //if there are any values that are still greater than 0, return false + //word = the word at any index of the array + //check each of those words against this.str } let myAnagram = new Anagram( 'hello' ) -console.log( myAnagram.matches( ['elloh'] ) ); +myAnagram.matches( ['olleh', 'goodbye']) + +module.exports = Anagram diff --git a/exercism/anagram/anagram.spec.js b/exercism/anagram/anagram.spec.js index ca71bd9..ee7a866 100644 --- a/exercism/anagram/anagram.spec.js +++ b/exercism/anagram/anagram.spec.js @@ -9,63 +9,63 @@ describe('Anagram', function() { expect(matches).toEqual([]); }); - xit('detects simple anagram',function() { + it('detects simple anagram',function() { var subject = new Anagram('ant'); var matches = subject.matches(['tan', 'stand', 'at']); expect(matches).toEqual(['tan']); }); - xit('does not detect false positives',function() { + it('does not detect false positives',function() { var subject = new Anagram('galea'); var matches = subject.matches(['eagle']); expect(matches).toEqual([]); }); - xit('detects multiple anagrams',function() { + it('detects multiple anagrams',function() { var subject = new Anagram('master'); var matches = subject.matches(['stream', 'pigeon', 'maters']); expect(matches).toEqual(['stream', 'maters']); }); - xit('does not detect anagram subsets',function() { + it('does not detect anagram subsets',function() { var subject = new Anagram('good'); var matches = subject.matches(['dog', 'goody']); expect(matches).toEqual([]); }); - xit('detects anagram',function() { + it('detects anagram',function() { var subject = new Anagram('listen'); var matches = subject.matches(['enlists', 'google', 'inlets', 'banana']); expect(matches).toEqual(['inlets']); }); - xit('detects multiple anagrams',function() { + it('detects multiple anagrams',function() { var subject = new Anagram('allergy'); var matches = subject.matches(['gallery', 'ballerina', 'regally', 'clergy', 'largely', 'leading']); expect(matches).toEqual(['gallery', 'regally', 'largely']); }); - xit('detects anagrams case-insensitively',function() { + it('detects anagrams case-insensitively',function() { var subject = new Anagram('Orchestra'); var matches = subject.matches(['cashregister', 'Carthorse', 'radishes']); expect(matches).toEqual(['Carthorse']); }); - xit('does not detect a word as its own anagram',function() { + it('does not detect a word as its own anagram',function() { var subject = new Anagram('banana'); var matches = subject.matches(['Banana']); expect(matches).toEqual([]); }); - xit('matches() accepts string arguments',function() { + it('matches() accepts string arguments',function() { var subject = new Anagram('ant'); var matches = subject.matches('stand', 'tan', 'at'); From cfcb6eb2521ef9ab5de189e5fe57695369364678 Mon Sep 17 00:00:00 2001 From: sashajustice Date: Thu, 6 Apr 2017 15:00:29 -0700 Subject: [PATCH 10/13] start code for etl --- exercism/etl/etl.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 exercism/etl/etl.js diff --git a/exercism/etl/etl.js b/exercism/etl/etl.js new file mode 100644 index 0000000..b0607be --- /dev/null +++ b/exercism/etl/etl.js @@ -0,0 +1,18 @@ +function Etl () { + this.{} = {}; + this.transformLetters {1 point: "A", "E", "I", "O", "U", "L", "N", "R", "S", "T", +2 points: "D", "G", +3 points: "B", "C", "M", "P", +4 points: "F", "H", "V", "W", "Y", +5 points: "K", +8 points: "J", "X", + 10 points: "Q", "Z",} + } +} + +Etl.prototype.transform = function () { + if( ) + +} + +module.exports = Etl From 30e3ddedfdce002692432426503216d2d7705da0 Mon Sep 17 00:00:00 2001 From: Monica Williams Date: Thu, 6 Apr 2017 16:16:48 -0700 Subject: [PATCH 11/13] things are working but the output is not alphabetized, the oldData is hardcoded --- exercism/etl/etl.js | 45 +++++++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/exercism/etl/etl.js b/exercism/etl/etl.js index b0607be..ea6601e 100644 --- a/exercism/etl/etl.js +++ b/exercism/etl/etl.js @@ -1,18 +1,39 @@ -function Etl () { - this.{} = {}; - this.transformLetters {1 point: "A", "E", "I", "O", "U", "L", "N", "R", "S", "T", -2 points: "D", "G", -3 points: "B", "C", "M", "P", -4 points: "F", "H", "V", "W", "Y", -5 points: "K", -8 points: "J", "X", - 10 points: "Q", "Z",} +function ETL() { + this.newData = {}; + this.transformLetters = { + 1: [ 'A', 'E', 'I', 'O', 'U', 'L', 'N', 'R', 'S', 'T' ], + 2: [ 'D', 'G' ], + 3: [ 'B', 'C', 'M', 'P' ], + 4: [ 'F', 'H', 'V', 'W', 'Y' ], + 5: [ 'K' ], + 8: [ 'J', 'X' ], + 10: [ 'Q', 'Z' ] } } -Etl.prototype.transform = function () { - if( ) +ETL.prototype.transform = function( oldData ) { + for ( prop in this.transformLetters ) { + var individualArray = this.transformLetters[prop] + + while ( individualArray.length > 0 ) { + var letter = individualArray.pop().toLowerCase() + this.newData[letter] = prop + } + } + + return this.newData } -module.exports = Etl +module.exports = ETL + +//loop through Object and record key. +//for each key, access array +//for each array, pop off until the array is empty + //as we pop off, push value.lowerCase to this.newData as the key, and the key of the array as the value +//return newData + +var scrabble = new ETL() +console.log(scrabble.transform()) + +//this.transformLetters[prop] gets us all of the arrays without their keys From 1a223c906c698ec7f018ed81d9046dde38d5d2a7 Mon Sep 17 00:00:00 2001 From: Monica Williams Date: Thu, 6 Apr 2017 17:38:04 -0700 Subject: [PATCH 12/13] implementation done, all tests passing --- exercism/etl/etl.js | 35 ++++++++--------------------------- exercism/etl/etl.spec.js | 7 ++++--- 2 files changed, 12 insertions(+), 30 deletions(-) diff --git a/exercism/etl/etl.js b/exercism/etl/etl.js index ea6601e..c9b8f05 100644 --- a/exercism/etl/etl.js +++ b/exercism/etl/etl.js @@ -1,39 +1,20 @@ function ETL() { - this.newData = {}; - this.transformLetters = { - 1: [ 'A', 'E', 'I', 'O', 'U', 'L', 'N', 'R', 'S', 'T' ], - 2: [ 'D', 'G' ], - 3: [ 'B', 'C', 'M', 'P' ], - 4: [ 'F', 'H', 'V', 'W', 'Y' ], - 5: [ 'K' ], - 8: [ 'J', 'X' ], - 10: [ 'Q', 'Z' ] - } + } ETL.prototype.transform = function( oldData ) { - for ( prop in this.transformLetters ) { - var individualArray = this.transformLetters[prop] + var newData = {} + + for ( prop in oldData ) { + var individualArray = oldData[prop] while ( individualArray.length > 0 ) { var letter = individualArray.pop().toLowerCase() - this.newData[letter] = prop + + newData[letter] = Number(prop) } } - - return this.newData - + return newData } module.exports = ETL - -//loop through Object and record key. -//for each key, access array -//for each array, pop off until the array is empty - //as we pop off, push value.lowerCase to this.newData as the key, and the key of the array as the value -//return newData - -var scrabble = new ETL() -console.log(scrabble.transform()) - -//this.transformLetters[prop] gets us all of the arrays without their keys diff --git a/exercism/etl/etl.spec.js b/exercism/etl/etl.spec.js index f213284..3c1baaf 100644 --- a/exercism/etl/etl.spec.js +++ b/exercism/etl/etl.spec.js @@ -3,6 +3,7 @@ var ETL = require('./etl'); describe('Transform', function() { var etl = new ETL(); + it('transforms one value', function() { var old = { 1: ['A'] }; var expected = { a: 1 }; @@ -10,21 +11,21 @@ describe('Transform', function() { expect(etl.transform(old)).toEqual(expected); }); - xit('transforms more values', function() { + it('transforms more values', function() { var old = { 1: ['A', 'E', 'I', 'O', 'U'] }; var expected = { a: 1, e: 1, i: 1, o: 1, u: 1 }; expect(etl.transform(old)).toEqual(expected); }); - xit('transforms more keys', function() { + it('transforms more keys', function() { var old = { 1: ['A', 'E'], 2: ['D', 'G'] }; var expected = { a: 1, e: 1, d: 2, g: 2 }; expect(etl.transform(old)).toEqual(expected); }); - xit('transforms a full dataset', function() { + it('transforms a full dataset', function() { var old = { 1: [ 'A', 'E', 'I', 'O', 'U', 'L', 'N', 'R', 'S', 'T' ], 2: [ 'D', 'G' ], From 81f685b42ed3a895bb85f6899d500d66e2635573 Mon Sep 17 00:00:00 2001 From: Monica Williams Date: Sun, 9 Apr 2017 22:15:19 -0700 Subject: [PATCH 13/13] cleaning up for review --- exercism/anagram/anagram.js | 67 ------------------------------------- exercism/pangram/pangram.js | 27 --------------- 2 files changed, 94 deletions(-) delete mode 100644 exercism/anagram/anagram.js delete mode 100644 exercism/pangram/pangram.js diff --git a/exercism/anagram/anagram.js b/exercism/anagram/anagram.js deleted file mode 100644 index 8c38e4b..0000000 --- a/exercism/anagram/anagram.js +++ /dev/null @@ -1,67 +0,0 @@ -function Anagram( str ) { - this.str = str.toLowerCase(), - this.letterHash = {} -} - -Anagram.prototype.matches = function( ...input ) { - // loop through all chars in str and mark # of time each letter apears - let foundAnagrams = [] - this.hashLetterCount() - - // loop through all of the words we are checcking to see if they - // are anagrams of this.str - if ( input[0] instanceof Array ) { - - for( let word of input ) { - console.log('word', word) - if( this.isAnagram( word )) { - foundAnagrams.push(word) - } - } - } - - return foundAnagrams -} - -Anagram.prototype.hashLetterCount = function() { - for( let letter of this.str ){ - if( this.letterHash[letter] === undefined ) { - this.letterHash[letter] = 1 - } else { - this.letterHash[letter]++ - } - } -} - -Anagram.prototype.isAnagram = function( word ) { - word = word.toLowerCase() - if ( word === this.str ) { - return false - } - if ( word.length !== this.str.length ) { - return false - } - for( let letter of word ) { - console.log('word', word) - if( this.letterHash[letter] === undefined ) { - return false - } else { - this.letterHash[letter]-- - } - } - for( let letter in this.letterHash ) { - if ( this.letterHash[letter] > 0 ) { - return false - } - } - return true - //loop through letterHash. - //if there are any values that are still greater than 0, return false - //word = the word at any index of the array - //check each of those words against this.str -} - -let myAnagram = new Anagram( 'hello' ) -myAnagram.matches( ['olleh', 'goodbye']) - -module.exports = Anagram diff --git a/exercism/pangram/pangram.js b/exercism/pangram/pangram.js deleted file mode 100644 index 246b083..0000000 --- a/exercism/pangram/pangram.js +++ /dev/null @@ -1,27 +0,0 @@ -function Pangram( str ) { - this.str = str, - this.asciiLookup = { - a: 0, b: 0, c: 0, d: 0, e: 0, f: 0, g: 0, h: 0, i: 0, j: 0, k: 0, l: 0, m: 0, - n: 0, o: 0, p: 0, q: 0, r: 0, s: 0, t: 0, u: 0, v: 0, w: 0, x: 0, y: 0, z: 0 - } -} - -Pangram.prototype.isPangram = function() { - - if ( this.str.length < 1 || typeof this.str !== 'string' ) { - return false - } else { - this.str = this.str.toLowerCase() - for ( var i = 0; i < this.str.length; i++ ) { - this.asciiLookup[this.str[i]] = 1 - } - for ( var prop in this.asciiLookup ) { - if ( this.asciiLookup[prop] === 0 ) { - return false - } - } - return true - } -} - -module.exports = Pangram