Skip to content

Instantly share code, notes, and snippets.

@shuhaibzahir
Forked from jingsu96/medium-transducer5.js
Created July 24, 2021 04:49
Show Gist options
  • Save shuhaibzahir/51c654f7968bec823303fa4f6bc81123 to your computer and use it in GitHub Desktop.
Save shuhaibzahir/51c654f7968bec823303fa4f6bc81123 to your computer and use it in GitHub Desktop.

Revisions

  1. @jingsu96 jingsu96 created this gist Jul 24, 2021.
    17 changes: 17 additions & 0 deletions medium-transducer5.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    const reducer = (acc, val) => acc + val;

    // string
    reducer('Hello', ', World'); // Hello, World

    // number
    reducer(5, 20); // 25

    // object
    const objectReducer = (acc, val) => ({ ...acc, ...val });

    const myInfo = {
    name: 'Jing',
    email: '[email protected]',
    };

    objectReducer({ ...myInfo }, { phone: '0912345678' }); // {name: "Jing", email: "jingmultiplefive@gmail.com", phone: "0912345678"}