forked from alex-aaron/matchy-copy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.js
72 lines (59 loc) · 2.13 KB
/
functions.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
/**
* Part 2
*
* In this file, we're going to create some
* Functions to work with our data created in
* data.js.
*
* See the README for detailed instructions,
* and read every instruction carefully.
*/
//////////////////////////////////////////////////////////////////////
// Step 1 - Search ///////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
function search(array, string) {
for (var i = 0; i < array.length; i++){
if(array[i].name === string){
return array[i];
}
}
return null;
}
//////////////////////////////////////////////////////////////////////
// Step 2 - Replace //////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
function replace(animals, name, replacement){
for (var i = 0; i < animals.length; i++){
if(animals[i].name === name){
animals[i] = replacement;
}
}
return;
}
//////////////////////////////////////////////////////////////////////
// Step 3 - Remove ///////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
function remove(animals, name){
var newArr = animals.filter(animal => animal.name !== name);
animals.length = 0;
animals.push(newArr);
}
//////////////////////////////////////////////////////////////////////
// Step 4 - Add ///////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
function add(animals, animal){
}
/**
* You did it! You're all done with Matchy!
*/
//////////////////////////////////////////////////////////////////////
// DON'T REMOVE THIS CODE ////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
var search, replace, remove, add;
if((typeof process !== 'undefined') &&
(typeof process.versions.node !== 'undefined')) {
module.exports.search = search || null;
module.exports.replace = replace || null;
module.exports.remove = remove || null;
module.exports.add = add || null;
}