-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdata.js
138 lines (137 loc) · 6.56 KB
/
data.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
var explorerDataEn = {
'add': {
'end': {
'name': 'push',
'link_name': 'push',
'desc': 'Adds element(s) to the end of an array. Returns the modified array',
'text': "nums = [2, 3, 5] #=> [2, 3, 5]<br>nums << 8 #=> [2, 3, 5, 8]<br>nums.push(13, 21) #=> [2, 3, 5, 8, 13, 21]<br>nums.push(37) #=> [2, 3, 5, 8, 13, 21, 37]"
},
'start': {
'name': 'unshift',
'link_name': 'unshift',
'desc': 'Adds element(s) to the front of an array. Returns the modified array',
'text': 'nums = [4, 5, 6] #=> [4, 5, 6]<br>nums.unshift(3) #=> [3, 4, 5, 6]<br>nums.unshift(1, 2) #=> [1, 2, 3, 4, 5, 6]'
},
'insert': {
'name': 'insert',
'link_name': 'insert',
'desc': 'Inserts the given element(s) before the element with the given index. Returns the modified array',
'text': "nums = [3, 4, 5, 6] #=> [4, 5, 6]<br>nums.insert(2, 9) #=> [3, 4, 9, 6]<br>nums.insert(2, 'one', 1) #=>[3, 4, \"one\", 1, 9, 6]"
},
'concat': {
'name': '+',
'link_name': '2B',
'desc': 'Returns a new array built by adding (concatenating) two arrays together',
'text': "nums = [4, 5, 6] #=> [4, 5, 6]<br>more_nums = nums + [1, 2] #=> [4, 5, 6, 1, 2]<br>nums #=> [4, 5, 6]<br><br>[4, 5, 6] + [1, 2] #=> [4, 5, 6, 1, 2]"
}
},
'rm': {
'end': {
'name': 'pop',
'link_name': 'pop',
'desc': 'Removes the last n elements from the array and returns it. Returns nil if the array is empty',
'text': "nums = [4, 5, 6] #=> [4, 5, 6]<br>nums.pop #=> 6<br>nums #=> [4, 5]<br><br>nums.pop(2) #=> [4, 5]<br>nums #=> []<br><br>nums.pop #=> nil<br>nums #=> []"
},
'start': {
'name': 'shift',
'link_name': 'shift',
'desc': 'Adds the last n elements to the array and returns it. Returns nil if the array is empty',
'text': 'nums = [4, 5, 6] #=> [4, 5, 6]<br>nums.shift #=> 4<br>nums #=> [5, 6]<br><br>nums.shift(2) #=> [5, 6]<br>nums #=> []<br><br>nums.shift #=> nil<br>nums #=> []'
},
'delete_at': {
'name': 'delete_at',
'link_name': 'delete_at',
'desc': 'Deletes the element at the given index and returns that element. Returns nil if the index is out of range',
'text': "nums = [4, 5, 6] #=> [4, 5, 6]<br>nums.delete_at(1) #=> 5<br>nums #=> [4, 6]<br><br>nums.delete_at(99) #=> nil"
},
'delete': {
'name': 'delete',
'link_name': 'delete',
'desc': 'Delete all items from the array that are equal to the given element. Returns the last deleted item or nil if no matching item is found',
'text': "nums = [4, 5, 5, 6] #=> [4, 5, 5, 6]<br>nums.delete(2) #=> nil<br>nums #=> [4, 5, 5, 6]<br><br>nums.delete(5) #=> 5<br>nums #=> [4, 6]"
},
'compact': {
'name': 'compact',
'link_name': 'compact',
'desc': 'Returns a copy of the original array with all nil elements removed.',
'text': "items = [nil, 4, nil, 6, nil, nil] #=> [nil, 4, nil, 6, nil, nil]<br>items.compact #=> [4, 6]<br>items #=> [nil, 4, nil, 6, nil, nil]"
},
'uniq': {
'name': 'uniq',
'link_name': 'uniq',
'desc': 'Returns a copy of the original array with all duplicate elements removed.',
'text': "nums = [5, 4, 5, 1, 7, 5, 1] #=> [5, 4, 5, 6, 7, 5, 1]<br>nums.uniq #=> [4, 7]<br>nums #=> [5, 4, 5, 6, 7, 5, 1]"
}
},
'find': {
'specific': {
'name': '[]',
'link_name': '5B-5D',
'desc': 'Returns the element at the specified index(es)',
'text': "nums = [1, 2, [3, 3.5]] #=> [1, 2, [3, 3.5]]<br>nums[0]#=> 1<br>nums[2, 1] #=> 3.5"
},
'match': {
'name': 'select',
'link_name': 'select',
'desc': 'Returns a new array containing all elements of the original array for which the given block returns a true value',
'text': 'nums = [4, 5, 6] #=> [4, 5, 6]<br>nums.select { |num| num.even? } #=> [4, 6]'
},
'include': {
'name': 'include',
'link_name': 'include-3F',
'desc': 'Returns true if the given object is in the array. otherwise, returns false',
'text': 'nums = [4, 5, 6] #=> [4, 5, 6]<br>nums.include?(3) #=> false<br>nums.include?(4) #=> true'
},
'bsearch': {
'name': 'bsearch',
'link_name': 'bsearch',
'desc': 'Uses binary search to find a value in a sorted array that meets a given condition. Returns nil if not found',
'text': "nums = [0, 4, 7, 10, 12]<br>nums.bsearch {|x| x >= 4 } #=> 4<br>nums.bsearch {|x| x >= 6 } #=> 7<br>nums.bsearch {|x| x >= -1 } #=> 0<br>nums.bsearch {|x| x >= 100 } #=> nil<br>nums.bsearch{|x| x == 7 } => 7<br>nums.bsearch {|x| x == 6 } #=> nil"
}
},
'iter': {
'each': {
'name': 'each',
'link_name': 'each',
'desc': 'calls the given block once for each element in the array. Returns the original array',
'text': "nums = [4, 5, 6] #=> [4, 5, 6]<br>nums.each{|x| print x+1} #=> [4, 5, 6]<br>#the command above prints '567' and returns [4, 5, 6]"
},
'map': {
'name': 'map',
'link_name': 'map',
'desc': 'calls the given block once for each element in the array. Returns the original array, whose values have been replaced by the values returned by the block',
'text': 'nums = [4, 5, 6] #=> [4, 5, 6]<br>nums.each{|x| x+10} #=> [14, 15, 16]'
}
},
'sort': {
'reverse': {
'name': 'reverse',
'link_name': 'reverse',
'desc': "Returns a new array containing the original array's elements in reverse order. <br><br><code>reverse</code> does not modify the original array. <code>reverse!</code> modifies the original array",
'text': "nums = [5, 4, 6] #=> [5, 4, 6]<br>nums.reverse #=> [6, 4, 5]<br>nums #=> [5, 4, 6]<br><br>nums.reverse! #=> [6, 4, 5]<br>nums #=> [6, 4, 5]"
},
'sort': {
'name': 'sort',
'link_name': 'sort',
'desc': 'Returns a new array created by sorting the original array.<br><code>sort</code> does not modify the original array. <code>sort!</code> modifies the original array',
'text': "nums = [5, 4, 6] #=> [5, 4, 6]<br>nums.sort #=> [4, 5, 6]<br><br>nums #=> [5, 4, 6]<br>nums.sort! #=> [4, 5, 6]<br>nums #=> [4, 5, 6]<br>"
}
},
'other': {
'length': {
'name': 'length',
'link_name': 'length',
'desc': 'Returns the length of an array. Length may be 0.',
'text': "nums = [4, 5, 6] #=> [4, 5, 6]<br>nums.length #=> 3"
},
'empty': {
'name': 'empty',
'link_name': 'empty-3F',
'desc': 'Returns true if the array has no elements. otherwise, returns false',
'text': 'nums = [4, 5, 6] #=> [4, 5, 6]<br>nums.empty? #=> false<br><br>nums = [] #=> []<br>nums.empty? #=> true'
}
}
};
var explorerData = {
'en': explorerDataEn
}