-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
27 lines (20 loc) · 985 Bytes
/
test.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
function convertTextToObject(input) {
const objects = [];
const lines = input.split('Class:').map(line => line.trim());
for (let i = 1; i < lines.length; i++) {
const classInfo = lines[i].split('Time:');
const timeInfo = classInfo[1].split('Location:');
const locationInfo = timeInfo[1].split('Instructor:');
const instructorInfo = locationInfo[1];
const classObj = {
class: classInfo[0],
time: timeInfo[0],
location: locationInfo[0],
instructor: instructorInfo
};
objects.push(classObj);
}
return objects;
}
console.log(convertTextToObject(`
Class: البرمجة بلغة جافا Time: 9:30-10:30 Location: B203 Instructor: Dr Muhammad Jazi Bawaana Class: تصميم وادارة قواعد البيانات Time: 8:30-9:30 Location: A129 Instructor: Hamdi Ahmed Mohamed Al-Omari Class: تحليل وتصميم الخوارزميات Time: 12:30-1:30 Location: A105 Instructor: Dr.. Hassan Mouidi Al-Sarhan`));