forked from AllStarCodeOrg/TF_JavaScriptAssessment
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstringcleaning.js
More file actions
58 lines (40 loc) · 1.32 KB
/
Copy pathstringcleaning.js
File metadata and controls
58 lines (40 loc) · 1.32 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
function strClean(arrOfStrs){
//Your code goes here
// the output array
let newArr = [];
// temporary holding spaces for removing whitespace and nonzeroes
let result = "";
let digit = "";
for(let i=0; i < arrOfStrs.length; i++) {
// the given element of the array
result = arrOfStrs[i].trim();
// removes nonzeroes
for(let j=0; j < result.length; j++) {
digit = result.substring(j, j+1);
if(parseInt(digit, 10) != undefined) {
if(digit != 0 && digit != 1) {
result.replace(digit, "");
}
}
if(digit != 0 && digit != 1) {
result.replace(digit, "");
}
console.log(digit);
console.log(result);
}
// replaces 1 and 0 with one and zero
result.replace("1", "one");
result.replace("0", "zero");
// replaces spaces with underscores
result.replace(" ", "_");
// removing whitespace
newArr.push(result);
}
return(newArr);
}
console.log(strClean([" mem ", "ger ", " bee", "10023"]));
let p = "I want bacon";
j = p.replace("bacon", "hamburgers");
console.log(j);
// DO NOT EDIT THE LINE BELOW THIS
module.exports = strClean;