You are viewing a single comment's thread. Return to all comments →
JS:
function findIndex(array, element) { let firstIndex = 0; let lastIndex = array.length - 1; let indexOfElement; while (firstIndex <= lastIndex) { const middleIndex = Math.floor((firstIndex + lastIndex) / 2); if (array[middleIndex] === element) return middleIndex; if (array[middleIndex] > element) { lastIndex = middleIndex - 1; indexOfElement = middleIndex; } else { firstIndex = middleIndex + 1; indexOfElement = firstIndex; } } return indexOfElement; } function activityNotifications(expenditure, d) { let notifications = 0; const sorted = expenditure.slice(0, d).sort((a, b) => a - b); for (let i = d; i < expenditure.length; i++) { const median = d % 2 === 1 ? sorted[Math.floor(d / 2)] : (sorted[d / 2 - 1] + sorted[d / 2]) / 2; if (expenditure[i] >= 2 * median) notifications += 1; sorted.splice(findIndex(sorted, expenditure[i - d]), 1); sorted.splice(findIndex(sorted, expenditure[i]), 0, expenditure[i]); } return notifications; }
Seems like cookies are disabled on this browser, please enable them to open this website
Fraudulent Activity Notifications
You are viewing a single comment's thread. Return to all comments →
JS: