-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathtests.js
43 lines (39 loc) · 1.3 KB
/
tests.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
function removeSpaces(fullString) {
const noSpaces = `${fullString}`;
return noSpaces.replace(/\s/g, '');
}
function getLocation(string, start) {
const location = string.search(start);
return location;
}
function getItemNumber(string) {
const beginningLocation = getLocation(string, ':');
const endLocation = getLocation(string, 'Model');
const itemNumber = string.slice(beginningLocation + 1, endLocation);
return { itemNumber, endLocation };
}
function getModel(string) {
const beginningLocation = getLocation(string, ':');
const endModelLocation = getLocation(string, 'UPC');
const modelId = string.slice(beginningLocation + 1, endModelLocation);
return { modelId, endModelLocation };
}
function getUpc(string) {
return string.substr(4);
}
function cutString(string, endLocation) {
return string.substr(endLocation);
}
function getAllData(fullData) {
const item = {};
const noSpaces = removeSpaces(fullData);
const { itemNumber, endLocation } = getItemNumber(noSpaces);
const removeItemNumber = cutString(noSpaces, endLocation);
const { modelId, endModelLocation } = getModel(removeItemNumber);
const removeModel = cutString(removeItemNumber, endModelLocation);
const upc = getUpc(removeModel);
item.itemNumber = itemNumber;
item.model = modelId;
item.upc = upc;
return item;
}