forked from JoinCODED/PreCourse-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug-project.js
More file actions
50 lines (49 loc) · 1.21 KB
/
debug-project.js
File metadata and controls
50 lines (49 loc) · 1.21 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
/**
* generateIntegersArray(firstNumber, lastNumber):
* - receives two numbers
* - returns an array with the integers between the two numbers
*
* e.g.
* generateIntegersArray(2, 5) -> [2, 3, 4, 5]
* generateIntegersArray(4, 9) -> [4, 5, 6, 7, 8, 9]
*
*/
function generateIntegersArray(firstNumber, lastNumber) {
const integersArray = [];
while (firstNumber < lastNumber) {
integersArray.push(firstNumber);
firstNumber = firstNumber + 1;
}
return integersArray;
}
/**
* noZeroes(numberString):
* - receives a number as a string
* - removes any zeroes at the beginning and the end of the number string
* - returns the resulting number string without zeroes at the beginning or the end
*
* e.g.
* noZeroes("0011000") -> "11"
* noZeroes("0130401431400") -> "1304014314"
*
*/
function noZeroes(numberString) {
let New = [];
for (let i = 0; i < numberString.length; i++) {
New.push(numberString[i]);
}
New = New.join(``);
while (New.startsWith("0")) {
New = New.slice(1);
}
while (New.endsWith("0")) {
New = New.slice(0, -1);
}
return New;
}
//console.log(generateIntegersArray(3, 7));
//console.log(noZeroes("001100"));
module.exports = {
generateIntegersArray,
noZeroes,
};