-
Notifications
You must be signed in to change notification settings - Fork 127
Expand file tree
/
Copy pathfunctions.js
More file actions
136 lines (127 loc) · 3.29 KB
/
functions.js
File metadata and controls
136 lines (127 loc) · 3.29 KB
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
/**
* 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
}
// console.log(sumOdds([3, 7, 8, 15, 2, 1, 13]));
/**
* 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: You need to turn the string into an array first
* Another Hint: Use string methods to make it case-insensitive
*/
function characterCount(string, c) {
// Your code here
}
// console.log(characterCount("Character Count is clever", "c"));
/**
* largestIncrement(numbers):
* - receives an array of numbers
* - returns the largest difference between two consecutive numbers in the array
* - see example below for clarification
* - assume all differences are positive numbers
* 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
}
// console.log(largestIncrement([11, 35, 52, 14, 56, 601, 777, 888, 999]));
/**
* 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
}
// console.log(afterX([1, 2, 3, 4, 5, 6, 7, 8, 9], 3));
/**
* 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
}
// console.log(abbreviate("miss", "Stephane"));
/**
* 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
}
// console.log(isUpperCase("JCREW"));
/**
* 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
}
// console.log(elementInArray([5, 6, 7], 8));
module.exports = {
sumOdds,
characterCount,
largestIncrement,
afterX,
abbreviate,
isUpperCase,
elementInArray,
};