โจsplit into course names
require: str.replaceWhitespaces()
// ๅฆ๏ผ'ๅ่ชๆ1011010101(25)' -> 'ๅ่ชๆ'
function courseName(courseCode){
// 1. ็ง็ฎๅ็จฑ (้ๆธๅญใ็ฉบ็ฝใ้่)
// 2. ็ง็ฎไปฃ็ขผ (ๆธๅญ้้ ญใ่ฑๆธๅญๅพ็บ)
// 3. ๅญธ็ๆ็ธพ (ไธๅฐไบไฝๆธ)
// โญโโ 1 โโโฎ โญโโโ 2 โโโโฎ โญโ 3 โโฎ
const found = courseCode.match(/([^\d\s,]+)(\d[0-9A-Z]+)\((\d{1,2})\)/);
if(!found) return null;
return found[1]; // capture group 1
}
// ๅฆ๏ผ'ๅ่ชๆ1011010101(25),่ฑ่ชๆ1011010102(14)' -> ['ๅ่ชๆ', '่ฑ่ชๆ']
function splitIntoCourseNames(courseCodes){
return courseCodes
.replaceWhitespaces('') // ๅป็ฉบ็ฝ (string)
.split(',') // ็ง็ฎๅ็จฑ+็ง็ฎไปฃ็ขผ+ๅญธ็ๆ็ธพ (array)
.map(s => courseName(s)); // ็ง็ฎๅ็จฑ (array)
}
let courses = splitIntoCourseNames('ๅ่ชๆ1011010101(25),่ฑ่ชๆ1011010102(14),ๆธๅญธA1011010204(15),ๆญทๅฒ1011010309(32),่่ก็ๆดป101101050W(15),้ซ่ฒ1011010815(36),ๅๅญธๅธธ่ญ1013010101(12),ๆข็ฉถ่ๅฏฆไฝ๏ผๅฐ็่ไบบๆ็คพๆ็งๅญธ็ ็ฉถ101301030H(12)');
// [
// 'ๅ่ชๆ',
// '่ฑ่ชๆ',
// 'ๆธๅญธA',
// 'ๆญทๅฒ',
// '่่ก็ๆดป',
// '้ซ่ฒ',
// 'ๅๅญธๅธธ่ญ',
// 'ๆข็ฉถ่ๅฏฆไฝ๏ผๅฐ็่ไบบๆ็คพๆ็งๅญธ็ ็ฉถ'
// ]
Last updated