Skip to content

Instantly share code, notes, and snippets.

@DonerKebab
Last active December 17, 2019 06:49
Show Gist options
  • Save DonerKebab/54070485d52a1cc654d3313a1d59b62e to your computer and use it in GitHub Desktop.
Save DonerKebab/54070485d52a1cc654d3313a1d59b62e to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="">
</head>
<body>
<div id="grcEmployee">
</div>
<div id="saEmployee">
</div>
<div id="pmoEmployee">
</div>
<script>
const employeeList = [
{
id: 1,
name: "kien",
department: "GRC",
age: 40
},
{
id: 2,
name: "huyen",
department: "GRC",
age: 18
},
{
id: 3,
name: "hue",
department: "du3",
age: 22
},
{
id: 4,
name: "bao",
department: "SA",
age: 38
},
{
id: 5,
name: "hieu",
department: "SA",
age: 32
},
{
id: 6,
name: "thanh",
department: "PMO",
age: 30
},
{
id: 7,
name: "giang",
department: "PMO",
age: 26
}
]
let loadEmployee = () => {
// for danh sach employeeList để chuẩn hoá tên nhân viên
for(let i = 0; i < employeeList.length; i++) {
employeeList[i].name = standardizedName(employeeList[i].name);
}
// chia mang employeeList thành 3 mảng: grc, pmo, và sa
let grc = getEmployeeByDepartment('grc', employeeList);
// let sa
// let pmo
// sắp xếp lại dữ liệu của ba mảng ở trên theo age
grc = sortEmployeeByAge(grc);
// pmo = ...
// sa = ...
// show dữ liệu ra dạng table vào div có id tuơng ứng
representData(grc, "grcEmployee");
}
let getEmployeeByDepartment = (departmentName, employeeList) => {
let employee = [];
// lặp mảng employeeList, nếu nv nào có department = departmentName thì push vào mảng
return employee;
}
let sortEmployeeByAge = (employeeList) => {
let len = employeeList.length;
for (let i = 0; i < len; i++) {
let min = i;
for (let j = i + 1; j < len; j++) {
if (employeeList[min].age > employeeList[j].age) {
min = j;
}
}
if (min !== i) {
let tmp = employeeList[i];
employeeList[i] = employeeList[min];
employeeList[min] = tmp;
}
}
return employeeList;
}
let standardizedName = (employeeName) => {
let standardName = "";
return standardName;
}
let representData = (employeeArray, elementId) => {
// dữ liệu từ mảng employeeArray sẽ được xử lí cộng chuỗi để tạo thành một string dạng
// <table>........</table> sau đó set innerHtml cho thẻ có id = elementId
let tableContent = "";
document.getElementById(elementId).innerHTML = tableContent;
}
loadEmployee()
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment