forked from tim-hr/underbar-pt2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunderbar-pt2.js
88 lines (78 loc) · 2.63 KB
/
underbar-pt2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
const { each } = require('./underbar-pt1');
/**
* OBJECTS
* =======
*
* In this section, we'll look at a couple of helpers for merging objects.
*/
// Extend a given object with all the properties of the passed in
// object(s).
//
// Example:
// var obj1 = {key1: "something"};
// _.extend(obj1, {
// key2: "something new",
// key3: "something else new"
// }, {
// bla: "even more stuff"
// }); // obj1 now contains key1, key2, key3 and bla
const extend = function(obj) {
// Your code here
// Hint: remember that Array.from can convert an array-like object to handy-dandy array for you.
};
// Like extend, but doesn't ever overwrite a key that already
// exists in obj
const defaults = function(obj) {
// Your code here
};
/**
* FUNCTIONS
* =========
*
* Now we're getting into function decorators, which take in any function
* and return out a new version of the function that works somewhat differently
*/
// Return a function that can be called at most one time. Subsequent calls
// should return the previously returned value.
const once = function(func) {
// Hint: you're going to need to return another function that you create inside this function.
};
// Memorize an expensive function's results by storing them. You may assume
// that the function only takes primitives as arguments.
// memoize could be renamed to oncePerUniqueArgumentList; memoize does the
// same thing as once, but based on many sets of unique arguments.
//
// _.memoize should return a function that, when called, will check if it has
// already computed the result for the given argument and return that value
// instead if possible.
const memoize = function(func) {
// Hint: look up Function.apply
// Your code here
};
// Delays a function for the given number of milliseconds, and then calls
// it with the arguments supplied.
//
// The arguments for the original function are passed after the wait
// parameter. For example _.delay(someFunction, 500, 'a', 'b') will
// call someFunction('a', 'b') after 500ms
const delay = function(func, wait) {
// Hint: delay things with the global function setTimeout()
// Hint: look up Function.apply
};
// Randomizes the order of an array's contents.
//
// TIP: This function's test suite will ask that you not modify the original
// input array. For a tip on how to make a copy of an array, see:
// http://mdn.io/Array.prototype.slice
const shuffle = function(arr) {
// Hint: See http://bost.ocks.org/mike/shuffle/ for an in-depth explanation of the
// Fisher-Yates Shuffle
};
module.exports = {
extend: extend,
defaults: defaults,
once: once,
memoize: memoize,
delay: delay,
shuffle: shuffle
};