-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheat-sheet.html
168 lines (168 loc) · 7.67 KB
/
cheat-sheet.html
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Ruby and JS cheat sheet</title>
<link rel="stylesheet" href="Stylesheets/cheat-sheet-style.css">
<link href='http://fonts.googleapis.com/css?family=Cabin' rel='stylesheet' type='text/css'>
</head>
<body>
<header id="top">
<ul class="top-nav">
<li>
<figure>
<a target="_blanc" href="https://twitter.com/niceguykailash"><img src="imgs/kai.jpg" alt=""></a>
<figcaption>Kailash</figcaption>
</figure>
</li>
<li><p>Hi everyone, we are DevBootcamp students. We built a cheat sheet with some of the most popular Ruby and JavaScript functions. When you hover over the flash cards they will turn around and reveal information about the function in question. Feel free to send us an email if you have any comments! <a href="mailto:[email protected],[email protected]">E-mail us</a></p></li>
<li>
<figure>
<a target="_blanc" href="https://twitter.com/Iulia_Soimaru"><img src="imgs/iulia.jpg" alt=""></a>
<figcaption>Iulia</figcaption>
</figure>
</li>
</ul>
</header>
<main>
<section class="left">
<h2>Ruby methods</h2>
<div class="flashcard red">
<div class="front">String method <br>.concat</div>
<div class="description">Append—Concatenates the given object to str. If the object is an integer, it is considered as a codepoint, and is converted to a character before concatenation. <br><br>
<span>
a = "hello" <br>
a.concat(" world") <br>
#=> "hello world"
</span>
</div>
</div>
<div class="flashcard lightgreen">
<div class="front">String method <br>.squeeze</div>
<div class="description">Returns a new string where runs of the same character that occur in this set are replaced by a single character. If no arguments are given, all runs of identical characters are replaced by a single character. <br><br>
<span>
"yellow moon and sun".squeeze <br>
#=> "yelow mon and sun"
</span>
</div>
</div>
<div class="flashcard yellow">
<div class="front">Array method <br>.pop</div>
<div class="description">Removes the last element from self and returns it, or nil if the array is empty. If a number n is given, returns an array of the last n elements.<br><br>
<span>
a = [ "a", "b", "c", "d" ]<br>
a.pop #=> "d" <br>
a.pop(2) #=> ["d", "c"] <br>
a #=> ["a"]
</span>
</div>
</div>
<div class="flashcard lightturquoise">
<div class="front">Array method <br>.slice</div>
<div class="description">Returns the element at an index, or returns a subarray starting at the start index and continuing for length elements, or returns a subarray specified by range of indices.<br><br>
<span>
a = [ "a", "b", "c", "d", "e" ]<br>
a[2] + a[0] + a[1] #=> "cab"<br>
a[1, 2] #=> [ "b", "c" ]<br>
a[-3, 3] #=> [ "c", "d", "e" ]
</span>
</div>
</div>
<div class="flashcard orange">
<div class="front">Enumerable method <br>.find_all</div>
<div class="description">Returns an array containing all elements of enum for which the given block returns a true value. If no block is given, an Enumerator is returned instead.<br><br>
<span>
(1..10).find_all { |i| i % 3 == 0 }<br>
#=> [3, 6, 9]<br><br>
[1,2,3,4,5].find_all { |num| num.even? }<br>
#=> [2, 4]
</span>
</div>
</div>
<div class="flashcard lightviolet">
<div class="front">Enumerable method <br>.map</div>
<div class="description">Returns a new array with the results of running block once for every element in enum. If no block is given, an enumerator is returned instead.<br><br>
<span>
(1..4).map { |i| i*i } <br>
#=> [1, 4, 9, 16]<br><br>
array = ["a", "b", "c", "d"]<br>
array.map {|elem| elem + "1"} <br>
#=> ["a1", "b1", "c1", "d1"]
</span>
</div>
</div>
</section>
<section class="right">
<h2>JavaScript functions</h2>
<div class="flashcard lightred">
<div class="front">Array function <br>.push()</div>
<div class="description">The push() method adds one or more elements to the end of an array and returns the new length property of the object upon which the method was called. <br><br>
<span>
var sports = ['apple', 'orange'];<br>
sports.push('grape', 'blueberry'); <br>
#=> ["apple", "orange", "grape", "blueberry"]
</span>
</div>
</div>
<div class="flashcard green">
<div class="front">Array function <br>.toString()</div>
<div class="description">The toString() method returns a string representing the specified array and its elements. For Array objects, the toString method joins the array and returns one string containing each array element separated by commas.<br><br>
<span>
var array = ["me", "you", "he", "she"]<br>
array.toString()<br>
#=> "me,you,he,she"
</span>
</div>
</div>
<div class="flashcard lightyellow">
<div class="front">Math function <br>.floor()</div>
<div class="description">The Math.floor() function returns the largest integer less than or equal to a given number. Because floor() is a static method of Math, you always use it as Math.floor(), rather than as a method of a Math object you created (Math is not a constructor).<br><br>
<span>
var int = 45.89<br>
Math.floor(int)<br>
#=> 45
</span>
</div>
</div>
<div class="flashcard turquoise">
<div class="front">Math function <br>.max()</div>
<div class="description">The Math.max() function returns the largest of zero or more numbers. max() is also a static method of Math, you always use it as Math.max(), rather than as a method of a Math object you created (Math is not a constructor).<br><br>
<span>
c<br>
Math.max(a, b)<br>
#=> 50
</span>
</div>
</div>
<div class="flashcard lightorange">
<div class="front">String function <br>.toLowerCase()</div>
<div class="description">The toLowerCase() method returns the called string value converted to lowercase. toLowerCase() does not affect the value of the string variable str itself.<br><br>
<span>
var str = "ALPHABET"<br>
str.toLowerCase() <br>
#=> "alphabet"
</span>
</div>
</div>
<div class="flashcard violet">
<div class="front">String function <br>.includes()</div>
<div class="description">The includes() method determines whether one string may be found within another string, returning true or false as appropriate. <br><br>
<span>
var str = 'To be, or not to be, that is the question.';<br>
str.includes('To be')<br>
#=> true
</span>
</div>
</div>
</section>
</main>
<footer>
<div class="blog">
<h2>Check out our blog posts here:</h2>
<a href="http://iulia-soimaru.github.io/blog.html" target="_blank">Iulia</a>
<a href="http://kduraiswami.github.io/" target="_blank">Kailash</a>
</div>
<div class="scroll-up"><a href="#top"><img src="imgs/up_arrow.png" alt=""></a></div>
</footer>
</body>
</html>