Skip to content

Instantly share code, notes, and snippets.

@technikhil314
Created April 22, 2022 16:37
Show Gist options
  • Save technikhil314/adde52466934b3b0cf09fa2db5fb44e9 to your computer and use it in GitHub Desktop.
Save technikhil314/adde52466934b3b0cf09fa2db5fb44e9 to your computer and use it in GitHub Desktop.

Revisions

  1. technikhil314 renamed this gist Apr 22, 2022. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. technikhil314 created this gist Apr 22, 2022.
    15 changes: 15 additions & 0 deletions processLogs..js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    function processLogs(logs, threshold) {
    const n = logs.length;
    let transactionCountMap = new Map()
    for(let i=0;i<n;i++) {
    const log = logs[i];
    const [sender, recepient, amount] = log.split(" ");
    transactionCountMap.set(sender, (transactionCountMap.get(sender) || 0) + 1)
    if(sender !== recepient) {
    transactionCountMap.set(recepient, (transactionCountMap.get(recepient) || 0) + 1)
    }
    }
    const transactionCountEntries = Array.from(transactionCountMap.entries());
    const overThreshholdUsers = transactionCountEntries.filter(x => x[1] >= threshold).map(x => x[0]);
    return overThreshholdUsers.sort((x,y) => parseInt(x)-parseInt(y) > 0 ? 1 : -1)
    }