forked from JoinCODED/PreCourse-Project
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathproject.js
172 lines (161 loc) · 3.95 KB
/
project.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
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
169
170
171
172
/**
* REFERENCES:
* - String methods: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String#
*
* If you'd like to run your function to test it yourself,
* uncomment it from the bottom of this file, then run this
* file with `node project.js`.
*
* Good luck!
*/
/**
* sumOdds(numbers):
* - receives an array of numbers
* - returns the sum of only the ODD numbers
*
* e.g.
* sumOdds([1, 2, 3, 4, 5, 6, 7, 8, 9]) -> 25
* sumOdds([3, 7, 8, 15, 2, 1, 13]) -> 39
*/
function sumOdds(numbers) {
// Your code here
}
/**
* characterCount(string, c):
* - receives a string and a character
* - returns the number of times `c` occurs in the string
* - note: this has to be case-insensitive
*
* e.g.
* characterCount("Michael Stephenson", "e") -> 3
* characterCount("Character Count is clever", "c") -> 4
*
* Hint: Use string methods to make it case-insensitive
*/
function characterCount(string, c) {
// Your code here
}
/**
* differences(numbers):
* - receives an array of numbers
* - returns an array that has the difference in the values of the numbers array.
* - see example below for clarification.
*
* e.g.
* differences([1, 3, 7, 9, 12]) -> [2, 4, 2, 3]
* 3 - 1 = 2
* 7 - 3 = 4
* 9 - 7 = 2
* 12 - 9 = 3
*
* differences([11, 35, 52, 14, 56]) -> [24, 17, -38, 42]
*/
function differences(numbers) {
// Your code here
}
/**
* largestIncrement(numbers):
* - receives an array of numbers
* - returns the largest difference between two consecutive numbers in the array
* - see example below for clarification
*
* e.g.
* largestIncrement([1, 3, 7, 9, 12]) -> 4
* 3 - 1 = 2
* 7 - 3 = 4
* 9 - 7 = 2
* 12 - 9 = 3
* largest: 4
*
* largestIncrement([11, 35, 52, 14, 56, 601, 777, 888, 999]) -> 545
*/
function largestIncrement(numbers) {
// Your code here
}
/**
* afterX(numbers, x):
* - receives an array of numbers, and a number `x`.
* - returns an array of every number in `numbers` that occurs after `x`.
*
* - assume there are no duplicate numbers.
*
* e.g.
* afterX([1, 2, 3, 4, 5, 6, 7, 8, 9], 3) -> [4, 5, 6, 7, 8, 9]
* afterX([11, 35, 52, 14, 56, 601, 777, 888, 999], 52) -> [14, 56, 601, 777, 888, 999]
*/
function afterX(numbers, x) {
// Your code here
}
/**
* abbreviate(firstName, lastName):
* - receives a first name and a last name
* - returns the initials in uppercase
*
* e.g.
* abbreviate("Michael", "Singer") -> "MS"
* abbreviate("jordan", "peterson") -> "JP"
*
* Hint: Use string method .toUpperCase()
*/
function abbreviate(firstName, lastName) {
// Your code here
}
/**
* isUpperCase(string):
* - receives a string
* - returns true if the string is uppercase, false otherwise
*
* e.g.
* isUpperCase("Mickey S") -> false
* isUpperCase("JCREW") -> true
*
*/
function isUpperCase(string) {
// Your code here
}
/**
* elementInArray(numbers, x):
* - receives an array of numbers, and a number `x`.
* - returns true if `x` is found in the array, false otherwise
*
* e.g.
* elementInArray([5, 6, 7], 6) -> true
* elementInArray([5, 6, 7], 8) -> false
*
*/
function elementInArray(numbers, x) {
// Your code here
}
/**
* reverseString(string):
* - receives a string
* - returns the reverse of the string
*
* e.g.
* reverseString("string") -> "gnirts"
* reverseString("CODED") -> "DEDOC"
*
*/
function reverseString(string) {
// Your code here
}
// console.log(sumOdds([3, 7, 8, 15, 2, 1, 13]));
// console.log(characterCount("Character Count is clever", "c"));
// console.log(differences([11, 35, 52, 14, 56]));
// console.log(largestIncrement([11, 35, 52, 14, 56, 601, 777, 888, 999]));
// console.log(afterX([1, 2, 3, 4, 5, 6, 7, 8, 9], 3));
// console.log(abbreviate("miss", "Stephane"));
// console.log(isUpperCase("JCREW"));
// console.log(elementInArray([5, 6, 7], 8));
// console.log(reverseString("CODED"));
module.exports = {
sumOdds,
characterCount,
differences,
largestIncrement,
afterX,
abbreviate,
isUpperCase,
elementInArray,
reverseString,
};