Skip to content

Instantly share code, notes, and snippets.

@getify
Last active September 19, 2024 20:49
Show Gist options
  • Save getify/9d583553d5ada22917f488f01dbc78c2 to your computer and use it in GitHub Desktop.
Save getify/9d583553d5ada22917f488f01dbc78c2 to your computer and use it in GitHub Desktop.

Revisions

  1. getify revised this gist Sep 19, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion 1-imperative.js
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,7 @@ const buckets = [
    const specialValue = 42;

    let count = 0;
    for (let [ userID, bucket ] of Object.entries(buckets)) {
    for (const [ userID, bucket ] of Object.entries(buckets)) {
    if (isEligible(specialValue,userID)) {
    count++;
    bucket.add(specialValue);
  2. getify revised this gist Sep 19, 2024. 2 changed files with 6 additions and 6 deletions.
    6 changes: 3 additions & 3 deletions 1-imperative.js
    Original file line number Diff line number Diff line change
    @@ -2,16 +2,16 @@ function isEligible(value,userID) {
    // .. whatever arbitrary logic ..
    }

    var buckets = [
    const buckets = [
    user1: new Set(),
    user2: new Set(),
    user3: new Set(),
    user4: new Set()
    }

    var specialValue = 42;
    const specialValue = 42;

    var count = 0;
    let count = 0;
    for (let [ userID, bucket ] of Object.entries(buckets)) {
    if (isEligible(specialValue,userID)) {
    count++;
    6 changes: 3 additions & 3 deletions 2-filter-reducer.js
    Original file line number Diff line number Diff line change
    @@ -2,16 +2,16 @@ function isEligible(value,userID) {
    // .. whatever arbitrary logic ..
    }

    var buckets = [
    const buckets = [
    user1: new Set(),
    user2: new Set(),
    user3: new Set(),
    user4: new Set()
    }

    var specialValue = 42;
    const specialValue = 42;

    var count = (
    const count = (
    Object.entries(buckets)
    .filter(([userID,bucket]) => isEligible(specialValue,userID))
    .reduce((counter,[userID,bucket]) => (bucket.add(specialValue),counter+1),0)
  3. getify revised this gist Sep 19, 2024. 2 changed files with 2 additions and 2 deletions.
    2 changes: 1 addition & 1 deletion 1-imperative.js
    Original file line number Diff line number Diff line change
    @@ -20,5 +20,5 @@ for (let [ userID, bucket ] of Object.entries(buckets)) {
    }

    if (count >= 2) {
    console.log("at least 2 users were eligible for the magic value!");
    console.log("at least 2 users were eligible for the special value!");
    }
    2 changes: 1 addition & 1 deletion 2-filter-reducer.js
    Original file line number Diff line number Diff line change
    @@ -18,5 +18,5 @@ var count = (
    );

    if (count >= 2) {
    console.log("at least 2 users were eligible for the magic value!");
    console.log("at least 2 users were eligible for the special value!");
    }
  4. getify revised this gist Sep 19, 2024. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions 1-imperative.js
    Original file line number Diff line number Diff line change
    @@ -10,6 +10,7 @@ var buckets = [
    }

    var specialValue = 42;

    var count = 0;
    for (let [ userID, bucket ] of Object.entries(buckets)) {
    if (isEligible(specialValue,userID)) {
  5. getify created this gist Sep 19, 2024.
    23 changes: 23 additions & 0 deletions 1-imperative.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    function isEligible(value,userID) {
    // .. whatever arbitrary logic ..
    }

    var buckets = [
    user1: new Set(),
    user2: new Set(),
    user3: new Set(),
    user4: new Set()
    }

    var specialValue = 42;
    var count = 0;
    for (let [ userID, bucket ] of Object.entries(buckets)) {
    if (isEligible(specialValue,userID)) {
    count++;
    bucket.add(specialValue);
    }
    }

    if (count >= 2) {
    console.log("at least 2 users were eligible for the magic value!");
    }
    22 changes: 22 additions & 0 deletions 2-filter-reducer.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    function isEligible(value,userID) {
    // .. whatever arbitrary logic ..
    }

    var buckets = [
    user1: new Set(),
    user2: new Set(),
    user3: new Set(),
    user4: new Set()
    }

    var specialValue = 42;

    var count = (
    Object.entries(buckets)
    .filter(([userID,bucket]) => isEligible(specialValue,userID))
    .reduce((counter,[userID,bucket]) => (bucket.add(specialValue),counter+1),0)
    );

    if (count >= 2) {
    console.log("at least 2 users were eligible for the magic value!");
    }