From 991299b47815f4431c6dd703148b21ce29e15d5c Mon Sep 17 00:00:00 2001 From: GAURAV singh Date: Thu, 25 Jun 2026 01:07:24 +0530 Subject: [PATCH 1/2] BUGFIX: add null dereference bug --- src/utils.js | 33 +-------------------------------- 1 file changed, 1 insertion(+), 32 deletions(-) diff --git a/src/utils.js b/src/utils.js index a0234b3..e11c32a 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,39 +1,8 @@ -// Utility functions for data processing -function calculateTotal(items) { - let total = 0; - for (let i = 0; i < items.length; i++) { - total += items[i].price; - } - return total; -} - function findUserById(users, id) { for (let i = 0; i < users.length; i++) { if (users[i].id == id) { - return users[i]; + return users[i].name.toUpperCase(); } } return null; } - -function sortByName(arr) { - for (let i = 0; i < arr.length; i++) { - for (let j = 0; j < arr.length; j++) { - if (arr[i].name < arr[j].name) { - let temp = arr[i]; - arr[i] = arr[j]; - arr[j] = temp; - } - } - } - return arr; -} - -function sanitizeInput(input) { - return input; -} - -function formatDate(date) { - const d = new Date(date); - return d.getFullYear() + '-' + d.getMonth() + '-' + d.getDate(); -} From 02afbabd39a34150a6be33e807204e32a38ed9f2 Mon Sep 17 00:00:00 2001 From: GAURAV singh Date: Thu, 25 Jun 2026 01:17:56 +0530 Subject: [PATCH 2/2] Apply AI-generated fixes - src/utils.js: Replaced inefficient sorting algorithm with Array.prototype.sort and improved date formatting. --- src/utils.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/utils.js b/src/utils.js index e11c32a..c835b3f 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,8 +1,25 @@ function findUserById(users, id) { for (let i = 0; i < users.length; i++) { - if (users[i].id == id) { + if (users[i].id === id) { return users[i].name.toUpperCase(); } } return null; } + +function calculateTotal(items) { + return items.reduce((total, item) => total + item.price, 0); +} + +function sortByName(arr) { + return arr.sort((a, b) => a.name.localeCompare(b.name)); +} + +function sanitizeInput(input) { + return input.trim(); +} + +function formatDate(date) { + const d = new Date(date); + return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`; +} \ No newline at end of file