Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
6484bec
just got jest working
Cloudenvy7 Sep 6, 2018
9d2e8d1
got this new branch going
Cloudenvy7 Sep 6, 2018
8386efb
tried gettin on this on the bus
Cloudenvy7 Sep 6, 2018
167c00d
created challenge three file
Cloudenvy7 Sep 7, 2018
94ded6e
moved file into dir two-dimesionsalArray
Cloudenvy7 Sep 7, 2018
8e7f582
challenge four settup
Cloudenvy7 Sep 10, 2018
d6c47db
challenge five js created
Cloudenvy7 Sep 10, 2018
b12657a
created the intial file
Cloudenvy7 Sep 10, 2018
fe99612
passed the first
Cloudenvy7 Sep 11, 2018
defecaf
worked on the first 4
Cloudenvy7 Sep 11, 2018
31c2fbe
added the code to the file
Cloudenvy7 Sep 12, 2018
03a6c3d
set up the intial fitler code
Cloudenvy7 Sep 13, 2018
6caccb5
created base code
Cloudenvy7 Sep 14, 2018
a8852d7
added code to base file
Cloudenvy7 Sep 14, 2018
10dd9d6
got two code challenges to pass
Cloudenvy7 Sep 14, 2018
38f8d97
just smashed this challenge 01 and 02
Cloudenvy7 Sep 17, 2018
7f64aef
the changes made committing
Cloudenvy7 Sep 17, 2018
5a63c5d
starter code for challenge 10
Cloudenvy7 Sep 17, 2018
11a44b6
thought I'd have time to go over the code challenge
Cloudenvy7 Sep 18, 2018
94f8cbd
challenge 2/3 third kicked my ass
Cloudenvy7 Sep 19, 2018
4506d7a
sort the first two right, the 3rd kicked me
Cloudenvy7 Sep 19, 2018
9322f17
focused on the getting passed challenges up to date
Cloudenvy7 Sep 20, 2018
c6982f3
worked on challengeOne got to number5 in two hrs
Cloudenvy7 Sep 23, 2018
9154316
worked on challengeOne got to number5 in two hrs
Cloudenvy7 Sep 23, 2018
968256f
worked on all 3 challenges got 2/3'
Cloudenvy7 Sep 23, 2018
217aae1
turning in what I got
Cloudenvy7 Sep 24, 2018
612b902
made sure I got challenge03 pushing up
Cloudenvy7 Sep 24, 2018
7ccdcfb
working on first challenge
Cloudenvy7 Sep 24, 2018
64e51a6
did the 2nd challenge
Cloudenvy7 Sep 24, 2018
43001fa
passed challenge three
Cloudenvy7 Sep 24, 2018
a8e00dc
Merge pull request #10 from Cloudenvy7/codeCatchUp
Cloudenvy7 Sep 24, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
181 changes: 181 additions & 0 deletions chainingMethods/challenges-10.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@

'use strict';

// ------------------------------------------------------------------------------------------------
// CHALLENGE 1
//
// Write a function named count that, given an integer and an array of arrays, uses either
// filter, map, or reduce to count the amount of times the integer is present in the array of arrays.
//
// Note: You might need to use the same method more than once.
//
// For example, count(5, [[1, 3, 5, 7, 9], [5, 5, 5], [1, 2, 3]]) returns 4.
// ------------------------------------------------------------------------------------------------

const count = (target, input) => {
// Solution code here...
};

// ------------------------------------------------------------------------------------------------
// CHALLENGE 2
//
// Write a function that, given an array of integer arrays as input, either filter, map, or reduce
// to calculate the total sum of all the elements in the array.
//
// Note: You might need to use the same method more than once.
// ------------------------------------------------------------------------------------------------

const totalSum = (input) => {
// Solution code here...
};

// ------------------------------------------------------------------------------------------------
// CHALLENGE 3

// Write a function named divisibleByFiveTwoToThePower that accpets an array of arrays as input.
//
// This function should first remove any elements that are not numbers or are not divisible by five.
//
// This function should then raise 2 to the power of the resulting numbers, returning an array of arrays.
//
// For example, [ [0,2,5,4], [2,4,10], [] ] should return [ [1, 32], [1024], [] ].
// ------------------------------------------------------------------------------------------------

const divisibleByFiveTwoToThePower = (input) => {
// Solution code here...
};

// ------------------------------------------------------------------------------------------------
// CHALLENGE 4
//
// Write a function named findMaleAndFemale that, given the Star Wars data, below,
// returns the names of the characters whose gender is either male or female.
//
// The names should be combined into a single string with each character name separated by "and".
//
// For example, "C-3PO and Luke Skywalker".
// ------------------------------------------------------------------------------------------------

let starWarsData = [{
name: 'Luke Skywalker',
height: '172',
mass: '77',
hair_color: 'blond',
skin_color: 'fair',
eye_color: 'blue',
birth_year: '19BBY',
gender: 'male',
},
{
name: 'C-3PO',
height: '167',
mass: '75',
hair_color: 'n/a',
skin_color: 'gold',
eye_color: 'yellow',
birth_year: '112BBY',
gender: 'n/a'},
{
name: 'R2-D2',
height: '96',
mass: '32',
hair_color: 'n/a',
skin_color: 'white, blue',
eye_color: 'red',
birth_year: '33BBY',
gender: 'n/a'
},
{
name: 'Darth Vader',
height: '202',
mass: '136',
hair_color: 'none',
skin_color: 'white',
eye_color: 'yellow',
birth_year: '41.9BBY',
gender: 'male'
},
{
name: 'Leia Organa',
height: '150',
mass: '49',
hair_color: 'brown',
skin_color: 'light',
eye_color: 'brown',
birth_year: '19BBY',
gender: 'female'
}]

let findMaleAndFemale = (data) => {
// Solution code here...
}

// ------------------------------------------------------------------------------------------------
// CHALLENGE 5

// Write a function named findShortest that, given the Star Wars data from challenge 6,
// uses any combination of filter, map and reduce to return the name of the shortest character.
//
// ------------------------------------------------------------------------------------------------

let findShortest = (data) => {
// Solution code here...
}

// ------------------------------------------------------------------------------------------------
// TESTS
//
// All the code below will verify that your functions are working to solve the challenges.
//
// DO NOT CHANGE any of the below code.
//
// Run your tests from the console: jest challenges-10.test.js
//
// ------------------------------------------------------------------------------------------------

describe('Testing challenge 1', () => {
test('It should return the number of times the input is in the nested arrays', () => {
expect(count(5, [[1, 3, 5, 7, 9], [5, 5, 5], [1, 2, 3]])).toStrictEqual(4);
expect(count(3, [[1, 3, 5, 7, 9], [5, 5, 5], [1, 2, 3]])).toStrictEqual(2);
expect(count(12, [[1, 3, 5, 7, 9], [5, 5, 5], [1, 2, 3]])).toStrictEqual(0);
});
test('It should work on empty arrays', () => {
expect(count(5, [[1, 3, 5, 7, 9], [], [5, 5, 5], [1, 2, 3], []])).toStrictEqual(4);
expect(count(5, [])).toStrictEqual(0);
})
});

describe('Testing challenge 2', () => {
test('It should add all the numbers in the arrays', () => {
const nums = [[1, 2, 3, 4, 5], [6, 7, 2, 4, 5, 7],[9, 2, 3, 6, ]];

expect(totalSum(nums)).toStrictEqual(66);
});
});

describe('Testing challenge 3', () => {
test('It should return numbers divisible by five, then raise two to the power of the resulting numbers', () => {
expect(divisibleByFiveTwoToThePower([[10, 20, 5, 4], [5, 6, 7, 9], [1, 10, 3]])).toStrictEqual([ [ 1024, 1048576, 32 ], [ 32 ], [ 1024 ] ]);
});

test('It should return an empty array if none of the numbers are divisible by five', () => {
expect(divisibleByFiveTwoToThePower([[1, 2, 3], [5, 10 , 15]])).toStrictEqual([ [], [ 32, 1024, 32768 ] ]);
});

test('It should return an empty array if the values are not numbers', () => {
expect(divisibleByFiveTwoToThePower([['one', 'two', 'five'], ['5', '10' , '15'], [5]])).toStrictEqual([ [], [], [ 32 ] ]);
});
});

describe('Testing challenge 4', () => {
test('It should return only characters that are male or female', () => {
expect(findMaleAndFemale(starWarsData)).toStrictEqual('Luke Skywalker and Darth Vader and Leia Organa');
expect(findMaleAndFemale([{name: 'person', gender: 'female'}, {gender: 'lol'}, {name: 'persontwo', gender: 'male'}])).toStrictEqual('person and persontwo');
});
});

describe('Testing challenge 5', () => {
test('It should return the shortest character', () => {
expect(findShortest(starWarsData)).toStrictEqual('Leia Organa');
});
});
162 changes: 162 additions & 0 deletions challenges-11.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
'use strict';

// ------------------------------------------------------------------------------------------------
// CHALLENGE 1
//
// Write a function named validatePin that uses a regular expression pattern to validate a PIN.
//
// If the PIN is four numerical digits long, return true. Otherwise, return false.
// ------------------------------------------------------------------------------------------------

const validatePin = (pin) => {
// Solution code here...
};

// ------------------------------------------------------------------------------------------------
// CHALLENGE 2
//
// Write a function named findTagNames that iterates over an array of HTML strings
// and uses a regular expression pattern to return the closing tags.
//
// For example, findTagNames(['<h1>Hello, world!</h1>', '<p>Welcome to my site</p>'])
// returns ['/h1', '/p'], and findTagNames(['<div><h1>Hello, world!</h1></div>', '<p>Welcome to my site</p>'])
// returns ['/h1', '/div', '/p'].
// ------------------------------------------------------------------------------------------------

const findTagNames = elements => {
// Solution code here...
}

// ------------------------------------------------------------------------------------------------
// CHALLENGE 3
//
// Write a function named validateEmail that takes in an email address and validates it based
// on several rules:
// - one word, or two words separated by a period, before the @ symbol
// - can contain numbers
// - can have any of the following top-level domains: .net, .com, or .org
// - no other special characters
// - no subdomains, ports, etc: must be of the form [email protected], not [email protected]:3000
//
// Return either true or false.
//
// Note: if you ever need to validate an email using a regex in practice, the Internet has the actual
// regex you should use. It's many many lines long.
// ------------------------------------------------------------------------------------------------

const validateEmail = (email) => {
// Solution code here...
};

// ------------------------------------------------------------------------------------------------
// CHALLENGE 4
//
// Write a function named validatePhoneNumber that accepts a phone number and determines if it is valid.
//
// Acceptable formats include:
// - (555) 555-5555
// - (555)555 5555
// - 555 555-5555
// - 555-5555555
// - 555-555 5555
// - 555-555-5555
// - 555 555 5555
// - 555555-5555
// - 5555555555
//
// Your function should include a single regular expression pattern that matches any of these formats.
//
// Return either true or false.
// ------------------------------------------------------------------------------------------------

const validatePhoneNumber = (phoneNumber) => {
// Solution code here...
};


// ------------------------------------------------------------------------------------------------
// TESTS
//
// All the code below will verify that your functions are working to solve the challenges.
//
// DO NOT CHANGE any of the below code.
//
// Run your tests from the console: jest solutions-11.test.js
//
// ------------------------------------------------------------------------------------------------

describe('Testing challenge 1', () => {
test('It should validate a PIN of exactly four digits', () => {
expect(validatePin(1234)).toBeTruthy();
expect(validatePin(123)).toBeFalsy();
expect(validatePin(12345)).toBeFalsy();
expect(validatePin('abcd')).toBeFalsy();
expect(validatePin('7890')).toBeTruthy();
expect(validatePin('0789')).toBeTruthy();
expect(validatePin(789)).toBeFalsy();
expect(validatePin('0000')).toBeTruthy();
});
});

describe('Testing challenge 2', () => {
test('It should return the closing tags', () => {
expect(findTagNames(['<h1>Hello, world!</h1>', '<p>Welcome to my site</p>'])).toStrictEqual([ '/h1', '/p' ]);
});
test('It should work if there are multiple closing tags in a single string', () => {
expect(findTagNames(['<div><h1>Hello, world!</h1></div>', '<p>Welcome to my site</p>'])).toStrictEqual([ '/h1', '/div', '/p' ]);
});
});

describe('Testing challenge 3', () => {
test('It should match a basic email', () => {
expect(validateEmail('[email protected]')).toBeTruthy();
});

test('It should match if the email contains a period', () => {
expect(validateEmail('[email protected]')).toBeTruthy();
});

test('It should match if the email contains other top-level domains', () => {
expect(validateEmail('[email protected]')).toBeTruthy();
});

test('It should match if the email contains a period and other top-level domains', () => {
expect(validateEmail('[email protected]')).toBeTruthy();
});

test ('It should fail things that aren\'t email addresses', () => {
expect(validateEmail('justastring')).toBeFalsy();
expect(validateEmail('missing@adomain')).toBeFalsy();
expect(validateEmail('@noname.com')).toBeFalsy();
expect(validateEmail('[email protected]')).toBeFalsy();
expect(validateEmail('[email protected]')).toBeFalsy();
expect(validateEmail('[email protected]')).toBeFalsy();
expect(validateEmail('missing.atsymbol.net')).toBeFalsy();
expect(validateEmail('[email protected]')).toBeFalsy();
expect(validateEmail('[email protected]')).toBeFalsy();
})
});

describe('Testing challenge 4', () => {
test('It should match the acceptable phone number formats', () => {
expect(validatePhoneNumber('(555) 555-5555')).toBeTruthy();
expect(validatePhoneNumber('555 555-5555')).toBeTruthy();
expect(validatePhoneNumber('555-555-5555')).toBeTruthy();
expect(validatePhoneNumber('555 5555555')).toBeTruthy();
expect(validatePhoneNumber('5555555555')).toBeTruthy();
expect(validatePhoneNumber('234 567 8910')).toBeTruthy();
});
test('It should not match unacceptable phone number formats', () => {
expect(validatePhoneNumber('abcdefghij')).toBeFalsy();
expect(validatePhoneNumber('222 222 2222 ext. 2222')).toBeFalsy();
expect(validatePhoneNumber('(222 222-2222')).toBeFalsy();
expect(validatePhoneNumber('222 222-2222-')).toBeFalsy();
expect(validatePhoneNumber('(222 222- 2222')).toBeFalsy();
expect(validatePhoneNumber('(222 222 -2222')).toBeFalsy();
expect(validatePhoneNumber('523 555--5555')).toBeFalsy();
expect(validatePhoneNumber('55555555555')).toBeFalsy();
expect(validatePhoneNumber('55555555555')).toBeFalsy();
expect(validatePhoneNumber('55555555555')).toBeFalsy();
expect(validatePhoneNumber('55_55_5555')).toBeFalsy();
})
});
Loading