Skip to content

Commit b2098d3

Browse files
author
sunjieming
committed
Added callback tests and refactored test files
1 parent 3b245bd commit b2098d3

File tree

6 files changed

+352
-327
lines changed

6 files changed

+352
-327
lines changed

src/project-2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ const getBiggest = (x, y) => {
88
const greeting = (language) => {
99
// return a greeting for three different languages:
1010
// language: 'German' -> 'Guten Tag!'
11-
// language: 'English' -> 'Hello!'
1211
// language: 'Spanish' -> 'Hola!'
12+
// language: 'Chinese' -> 'Ni Hao!'
1313
// if language is undefined return 'Hello!'
1414
};
1515

src/project-4.js

Lines changed: 23 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,39 @@
1-
// Do not change any of the function names
2-
3-
const multiplyArguments = () => {
4-
// use the spread operator (...args) to multiply all of the arguments together and return the product
5-
// if no arguments are passed in return 0
6-
// if one argument is passed in just return it
7-
};
8-
9-
const invokeCallback = (cb) => {
10-
// invoke cb
11-
};
12-
13-
const sumArray = (numbers, cb) => {
14-
// sum up all of the integers in the numbers array
15-
// pass the result to cb
16-
// no return is necessary
1+
const getFirstItem = (collection, cb) => {
2+
// invoke the callback function and pass the first item from the collection in as an argument
173
};
184

19-
const forEach = (arr, cb) => {
20-
// iterate over arr and pass its values to cb one by one
21-
// hint: you will be invoking cb multiple times (once for each value in the array)
5+
const getLength = (collection, cb) => {
6+
// Write a function called getLength that passes the length of the array into the callback
227
};
238

24-
const map = (arr, cb) => {
25-
// create a new array
26-
// iterate over each value in arr, pass it to cb, then place the value returned from cb into the new arr
27-
// the new array should be the same length as the array argument
9+
const getLastItem = (collection, cb) => {
10+
// Write a function called getLastItem which passes the getLastItem item of the array into the callback
2811
};
2912

30-
const getUserConstructor = () => {
31-
// create a constructor called User
32-
// it should accept an options object with username, name, email, and password properties
33-
// in the constructor set the username, name, email, and password properties
34-
// the constructor should have a method 'sayHi' on its prototype that returns the string 'Hello, my name is {{name}}'
35-
// {{name}} should be the name set on each instance
36-
// return the constructor
13+
const sumNums = (x, y, cb) => {
14+
// Write a function called sumNums that adds two numbers and passes the result to the callback
3715
};
3816

39-
const addPrototypeMethod = (Constructor) => {
40-
// add a method to the constructor's prototype
41-
// the method should be called 'sayHi' and should return the string 'Hello World!'
17+
const multiplyNums = (x, y, cb) => {
18+
// Write a function called multiplyNums that adds two numbers and passes the result to the callback
4219
};
4320

44-
const addReverseString = () => {
45-
// add a method to the string constructor's prototype that returns a reversed copy of the string
46-
// name this method reverse
47-
// hint:
48-
// you will need to use 'this' inside of reverse
21+
const contains = (collection, item, cb) => {
22+
// Write a function called contains that checks if an item is present inside of the given array.
23+
// Pass true to the callback if it is, otherwise pass false
4924
};
5025

51-
const nFactorial = (n) => {
52-
// return the factorial for n
53-
// solve this recursively
54-
// example:
55-
// the factorial of 3 is 6 (3 * 2 * 1)
26+
const removeDuplicates = (collection, cb) => {
27+
// Write a function called removeDuplicates that removes all duplicate values from the given array.
28+
// Pass the array to the callback function. Do not mutate the original array.
5629
};
5730

58-
const cacheFunction = (cb) => {
59-
// Extra Credit
60-
// use closure to create a cache for the cb function
61-
// the function that you return should accept a single argument and invoke cb with that argument
62-
// when the function you return is invoked with an argument it should save that argument and its result
63-
// when the function you return is called again with an argument that it has seen before it should not call cb
64-
// but should instead directly returned the previous result
65-
// example:
66-
// cb -> function(x) { return x * x; }
67-
// if the function you return is invoked with 5 it would pass 5 to cb(5) and return 25
68-
// if the function you return is invoked again with 5 it will look on an object in the closure scope
69-
// and return 25 directly and will not invoke cb again
70-
};
71-
72-
73-
// Do not modify code below this line.
74-
// --------------------------------
75-
7631
module.exports = {
77-
multiplyArguments,
78-
invokeCallback,
79-
sumArray,
80-
forEach,
81-
map,
82-
getUserConstructor,
83-
addPrototypeMethod,
84-
addReverseString,
85-
nFactorial,
86-
cacheFunction
32+
getFirstItem,
33+
getLength,
34+
getLastItem,
35+
sumNums,
36+
multiplyNums,
37+
contains,
38+
removeDuplicates
8739
};

0 commit comments

Comments
 (0)