Skip to content

Instantly share code, notes, and snippets.

@novalagung
Last active April 8, 2018 02:35
Show Gist options
  • Save novalagung/948afd70540c2f7b59e6c841d426b126 to your computer and use it in GitHub Desktop.
Save novalagung/948afd70540c2f7b59e6c841d426b126 to your computer and use it in GitHub Desktop.
function fixData(src) {
backup = {}
dest = []
src.forEach(function (d) {
var pos = d.EmployeePosition
var posLower = pos.toLowerCase()
if (!backup.hasOwnProperty(posLower)) {
var beautyPos = pos.split(" ").map(function (e) {
if (e.length == 0) return ""
return e[0].toUpperCase() + e.slice(1)
}).join(" ")
backup[posLower] = beautyPos
}
d.EmployeePosition = backup[posLower]
dest.push($.extend(true, {}, d))
})
return dest
}
data = [
{ ClientName: "Pepsi", "EmployeeName": "Lorem", "EmployeePosition": "Director", TotalBillableAmount: 20000 },
{ ClientName: "Pepsi", "EmployeeName": "Ipsum", "EmployeePosition": "mAnager", TotalBillableAmount: 30000 },
{ ClientName: "Pepsi", "EmployeeName": "Dolor", "EmployeePosition": "Marketing", TotalBillableAmount: 25000 },
{ ClientName: "Pepsi", "EmployeeName": "Sit", "EmployeePosition": "iT Engineer", TotalBillableAmount: 21000 },
{ ClientName: "Pepsi", "EmployeeName": "Amet", "EmployeePosition": "IT Support", TotalBillableAmount: 17000 },
{ ClientName: "Pepsi", "EmployeeName": "Oli", "EmployeePosition": "sys Admin", TotalBillableAmount: 20000 },
{ ClientName: "Coca Cola", "EmployeeName": "Lorem", "EmployeePosition": "Director", TotalBillableAmount: 18000 },
{ ClientName: "Coca Cola", "EmployeeName": "Dolor", "EmployeePosition": "Marketing", TotalBillableAmount: 23000 },
{ ClientName: "Coca Cola", "EmployeeName": "Sit", "EmployeePosition": "iT Engineer", TotalBillableAmount: 19000 },
{ ClientName: "Coca Cola", "EmployeeName": "Oli", "EmployeePosition": "Sys Admin", TotalBillableAmount: 18700 }
]
data = fixData(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment