Skip to content

Commit ed003c0

Browse files
committed
adding starter code
1 parent 7de9a56 commit ed003c0

File tree

14 files changed

+62
-408
lines changed

14 files changed

+62
-408
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
11
// https://github.com/rithmschool/intermediate_javascript_exercises/blob/master/call_apply_bind_exercise/callApplyBindSpec.js
22

3-
function arrayFrom(arrayLikeObject){
4-
return [].slice.call(arrayLikeObject)
5-
}
3+
function arrayFrom(arrayLikeObject) {}
64

7-
function sumEvenArguments(){
8-
var newArgs = [].slice.call(arguments);
9-
return newArgs.reduce(function(acc,next){
10-
if(next % 2 === 0){
11-
return acc+next;
12-
}
13-
return acc;
14-
},0)
15-
}
5+
function sumEvenArguments() {}
166

177
// Write a function called sumEvenArguments which takes all of the arguments passed to a function and returns the sum of the even ones.
188

@@ -28,46 +18,15 @@ function sumEvenArguments(){
2818
// addOnlyThreeTimes(1,2) // 3
2919
// addOnlyThreeTimes(1,2) // "Maxed Out!"
3020

31-
32-
function add(a,b){
33-
return a+b
34-
}
35-
36-
function invokeMax(fn, num){
37-
var max = 0;
38-
return function(){
39-
if(max >= num) return "Maxed Out!";
40-
max++;
41-
return fn.apply(this,arguments);
42-
}
21+
function add(a, b) {
22+
return a + b;
4323
}
4424

45-
function once(fn, thisArg){
46-
var hasBeenCalled = false;
47-
return function(){
48-
if(!hasBeenCalled){
49-
hasBeenCalled = true;
50-
return fn.apply(thisArg, arguments)
51-
}
52-
}
53-
}
25+
function invokeMax(fn, num) {}
5426

55-
function bind(fn, thisArg){
56-
var outerArgs = [].slice.call(arguments,2)
57-
return function(){
58-
var innerArgs = [].slice.call(arguments)
59-
var allArgs = outerArgs.concat(innerArgs)
60-
return fn.apply(thisArg, allArgs)
61-
}
62-
}
27+
function once(fn, thisArg) {}
6328

29+
function bind(fn, thisArg) {}
6430

6531
// BONUS!
66-
function flip(fn, thisArg){
67-
var outerArgs = [].slice.call(arguments,2)
68-
return function(){
69-
var innerArgs = [].slice.call(arguments)
70-
var allArgs = outerArgs.concat(innerArgs).slice(0, fn.length)
71-
return fn.apply(thisArg, allArgs.reverse())
72-
}
73-
}
32+
function flip(fn, thisArg) {}
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,28 @@
11
// Write a function called specialMultiply which accepts two parameters. If the function is passed both parameters, it should return the product of the two. If the function is only passed one parameter - it should return a function which can later be passed another parameter to return the product. You will have to use closure and arguments to solve this.
22

3-
specialMultiply(3,4); // 12
3+
specialMultiply(3, 4); // 12
44
specialMultiply(3)(4); // 12
55
specialMultiply(3); // returns a function
66

7-
function specialMultiply(a,b){
8-
if(arguments.length === 1){
9-
return function(b){
10-
return a*b;
11-
}
12-
}
13-
return a*b;
14-
}
7+
function specialMultiply(a, b) {}
158

169
// Write a function called guessingGame which takes in one parameter amount. The function should return another function that takes in a parameter called guess. In the outer function, you should create a variable called answer which is the result of a random number between 0 and 10 as well as a variable called guesses which should be set to 0.
1710

1811
// In the inner function, if the guess passed in is the same as the random number (defined in the outer function) - you should return the string "You got it!". If the guess is too high return "Your guess is too high!" and if it is too low, return "Your guess is too low!". You should stop the user from guessing if the amount of guesses they have made is greater than the initial amount passed to the outer function.
1912

2013
// You will have to make use of closure to solve this problem.
2114

22-
function guessingGame(amount){
23-
var answer = Math.floor(Math.random()*11);
24-
var guesses = 0;
25-
var completed = false;
26-
return function(guess){
27-
if(!completed){
28-
guesses++
29-
if(guess === answer) {
30-
completed = true;
31-
return "You got it!"
32-
}
33-
else if(guess > answer) return "Your guess is too high!"
34-
else if(guess < answer) return "Your guess is too low!"
35-
else if(guesses === amount) {
36-
completed = true;
37-
return "No more guesses the answer was " + answer;
38-
}
39-
}
40-
return "All done playing!"
41-
}
42-
}
43-
44-
var game = guessingGame(5)
45-
game(1) // "You're too low!"
46-
game(8) // "You're too high!"
47-
game(5) // "You're too low!"
48-
game(7) // "You got it!"
49-
game(1) // "You are all done playing!"
50-
51-
var game2 = guessingGame(3)
52-
game2(5) // "You're too low!"
53-
game2(3) // "You're too low!"
54-
game2(1) // "No more guesses the answer was 0"
55-
game2(1) // "You are all done playing!"
15+
function guessingGame(amount) {}
16+
17+
var game = guessingGame(5);
18+
game(1); // "You're too low!"
19+
game(8); // "You're too high!"
20+
game(5); // "You're too low!"
21+
game(7); // "You got it!"
22+
game(1); // "You are all done playing!"
23+
24+
var game2 = guessingGame(3);
25+
game2(5); // "You're too low!"
26+
game2(3); // "You're too low!"
27+
game2(1); // "No more guesses the answer was 0"
28+
game2(1); // "You are all done playing!"

es2015-16-17-part-1/arrow-functions/arrow-functions-exercises.js

+5-15
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
// }
88

99
// 1
10-
let tripleAndFilter = arr => arr.map(val => val * 3).filter(val => val % 5 === 0);
1110

1211
// function doubleOddNumbers(arr){
1312
// return arr.filter(function(val){
@@ -18,7 +17,6 @@ let tripleAndFilter = arr => arr.map(val => val * 3).filter(val => val % 5 === 0
1817
// }
1918

2019
// 2
21-
let doubleOddNumbers = arr => arr.filter(val => val % 2 !== 0).map(val => val * 2 );
2220

2321
// function mapFilterAndReduce(arr){
2422
// return arr.map(function(val){
@@ -32,23 +30,15 @@ let doubleOddNumbers = arr => arr.filter(val => val % 2 !== 0).map(val => val *
3230
// }
3331

3432
// 3
35-
let mapFilterAndReduce = (arr) => arr.map(val => val.firstName).filter(val => val.length < 5)
36-
.reduce((acc,next) => {
37-
acc[next] = next.length
38-
return acc;
39-
}, {})
4033

4134
// 4
42-
let createStudentObj = (firstName, lastName) => ({firstName:firstName, lastName,lastName})
4335

4436
// 5
4537
var instructor = {
4638
firstName: "Colt",
47-
sayHi: function(){
48-
setTimeout(function(){
49-
console.log('Hello ' + this.firstName)
50-
},1000)
39+
sayHi: function() {
40+
setTimeout(function() {
41+
console.log("Hello " + this.firstName);
42+
}, 1000);
5143
}
52-
}
53-
54-
instructor.sayHi();
44+
};
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,7 @@
1-
function displayStudentInfo(obj){
2-
var {first, last} = obj;
3-
return `Your full name is ${first} ${last}`
4-
}
1+
function displayStudentInfo(obj) {}
52

6-
function printFullName({first,last}){
7-
return `Your full name is ${first} ${last}`
8-
}
3+
function printFullName({ first, last }) {}
94

10-
function createStudent({likesJavaScript = true, likesES2015 = true} = {}){
11-
var start = 'The student';
12-
if(likesJavaScript && likesES2015){
13-
start += ' likes JavaScript and ES2015'
14-
} else if(likesJavaScript){
15-
start += ' likes JavaScript!'
16-
} else if(likesES2015){
17-
start += ' likes ES2015!'
18-
} else {
19-
start += ' does not like much...'
20-
}
21-
return start;
22-
}
23-
24-
function reverseArray(arr){
25-
for(var i = 0; i < arr.length/2; i++){
26-
[arr[i], arr[arr.length - 1 - i]] = [arr[arr.length - 1 - i], arr[i]]
27-
}
28-
return arr;
29-
}
5+
function createStudent({ likesJavaScript = true, likesES2015 = true } = {}) {}
306

7+
function reverseArray(arr) {}
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,17 @@
11
// spread
2-
function smallestValue(...args){
3-
return Math.min(...args)
4-
}
2+
function smallestValue(...args) {}
53

64
// placeInMiddle([1,2,6,7],[3,4,5])
7-
function placeInMiddle(arr, vals){
8-
let mid = Math.floor(arr.length/2)
9-
arr.splice(mid,0,...vals)
10-
return arr;
11-
}
5+
function placeInMiddle(arr, vals) {}
126

137
// rest
14-
function joinArrays(...args){
15-
return args.reduce((acc, next) => acc.concat(next), [])
16-
}
8+
function joinArrays(...args) {}
179

1810
// rest
19-
function sumEvenArgs(...args){
20-
return args.reduce((acc, next) => next % 2 === 0 ? acc += next : acc, 0)
21-
}
11+
function sumEvenArgs(...args) {}
2212

2313
// rest
24-
function flip(fn, thisArg, ...outerArgs){
25-
return function(...innerArgs){
26-
let allArgs = outerArgs.concat(innerArgs).slice(0, fn.length)
27-
return fn.apply(thisArg, allArgs.reverse());
28-
}
29-
}
14+
function flip(fn, thisArg, ...outerArgs) {}
3015

3116
// rest + spread
32-
function bind(fn, thisArg, ...outerArgs){
33-
return function(...innerArgs){
34-
return fn.apply(thisArg, [...outerArgs, ...innerArgs])
35-
}
36-
}
17+
function bind(fn, thisArg, ...outerArgs) {}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
// Write a method called multiplyFavoriteNumber that takes in a number and returns the product of the number and the Person's favorite number
32

43
// function Person(firstName, lastName, favoriteColor, favoriteNumber){
@@ -11,24 +10,4 @@
1110
// }
1211
// }
1312

14-
class Person {
15-
constructor(firstName, lastName, favoriteColor, favoriteNumber){
16-
this.firstName = firstName;
17-
this.lastName = lastName;
18-
this.favoriteColor = favoriteColor;
19-
this.favoriteNumber = favoriteNumber;
20-
this.family = [];
21-
}
22-
fullName(){
23-
return `${this.firstName} ${this.lastName}`
24-
}
25-
multiplyFavoriteNumber(num){
26-
return num * this.favoriteNumber;
27-
}
28-
addToFamily(obj){
29-
if(obj.constructor === Person && this.family.indexOf(obj) === -1){
30-
this.family.push(obj)
31-
}
32-
return this.family
33-
}
34-
}
13+
class Person {}
Original file line numberDiff line numberDiff line change
@@ -1,27 +1 @@
1-
class Vehicle {
2-
constructor(make,model,year){
3-
this.make = make;
4-
this.model = model;
5-
this.year = year;
6-
}
7-
start(){
8-
return "VROOM!"
9-
}
10-
toString(){
11-
return `The make, model, and year are ${this.make} ${this.model} ${this.year}`;
12-
}
13-
}
14-
15-
class Car extends Vehicle {
16-
constructor(make,model,year){
17-
super(...arguments)
18-
this.numWheels = 4;
19-
}
20-
}
21-
22-
class Motorcycle extends Vehicle {
23-
constructor(make,model,year){
24-
super(...arguments)
25-
this.numWheels = 2;
26-
}
27-
}
1+
class Vehicle {}

es2015-16-17-part-2/es2015-methods/es2015-methods-exercises.js

+5-15
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,12 @@
22
// Object.assign
33
// Number.isFinite
44

5-
function copyObject(obj){
6-
return Object.assign({}, obj)
7-
}
5+
function copyObject(obj) {}
86

9-
function checkIfFinite(num){
10-
return Number.isFinite(num)
11-
}
7+
function checkIfFinite(num) {}
128

13-
function areAllNumbersFinite(arr){
14-
return arr.every(Number.isFinite)
15-
}
9+
function areAllNumbersFinite(arr) {}
1610

17-
function convertArrayLikeObject(obj){
18-
return Array.from(obj)
19-
}
11+
function convertArrayLikeObject(obj) {}
2012

21-
function displayEvenArguments(){
22-
return Array.from(arguments).filter(val => val % 2 === 0);
23-
}
13+
function displayEvenArguments() {}

0 commit comments

Comments
 (0)