From c23bf57bc1bbfbe3134b6b336503779efa6d302e Mon Sep 17 00:00:00 2001 From: Ratan Gulati Date: Wed, 19 Nov 2025 08:40:54 +0530 Subject: [PATCH] Add sample code for AI review --- sample-code.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 sample-code.js diff --git a/sample-code.js b/sample-code.js new file mode 100644 index 0000000..add7930 --- /dev/null +++ b/sample-code.js @@ -0,0 +1,33 @@ +// Sample code with various issues for AI review +function calculateTotal(items) { + let total = 0; + for (let i = 0; i < items.length; i++) { + total = total + items[i].price; + } + return total; +} + +// Missing error handling +function fetchUserData(userId) { + return fetch(`https://api.example.com/users/${userId}`) + .then(response => response.json()); +} + +// Security issue: SQL injection vulnerability +function getUser(username) { + const query = "SELECT * FROM users WHERE username = '" + username + "'"; + return db.query(query); +} + +// Performance issue: inefficient loop +function findDuplicates(arr) { + let duplicates = []; + for (let i = 0; i < arr.length; i++) { + for (let j = i + 1; j < arr.length; j++) { + if (arr[i] === arr[j]) { + duplicates.push(arr[i]); + } + } + } + return duplicates; +}