Skip to content

Instantly share code, notes, and snippets.

@aaronranard
Last active February 15, 2018 23:26
Show Gist options
  • Select an option

  • Save aaronranard/c82582b47dc6cd4a2a2ed8d956126c2c to your computer and use it in GitHub Desktop.

Select an option

Save aaronranard/c82582b47dc6cd4a2a2ed8d956126c2c to your computer and use it in GitHub Desktop.

Revisions

  1. aaronranard revised this gist Feb 15, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion key-value-transform.js
    Original file line number Diff line number Diff line change
    @@ -15,5 +15,5 @@ const backToKeyValueObj = keyValueArray.reduce((obj, { key, value }) => ({ ...ob

    /**
    * backToKeyValueObj:
    * { "api_url": "https://hawaii.usa.gov", "message": "BALLISTIC MISSILE INBOUND. THIS IS NOT A DRILL.", "is_drill": true }
    * { "api_url": "https://hawaii.usa.gov", "message": "BALLISTIC MISSILE INBOUND.", "is_drill": true }
    */
  2. aaronranard revised this gist Feb 15, 2018. 1 changed file with 19 additions and 2 deletions.
    21 changes: 19 additions & 2 deletions key-value-transform.js
    Original file line number Diff line number Diff line change
    @@ -1,2 +1,19 @@
    const keyValueObj = { "key": "value", "key2": "value2", "key3": "value3" };
    const keyValueArray = Object.entries(keyValueObj).map(([key, value]) => ({ key, value }));
    const keyValueObj = { "api_url": "https://hawaii.usa.gov", "message": "BALLISTIC MISSILE INBOUND.", "is_drill": true };

    const keyValueArray = Object.entries(keyValueObj).map(([key, value]) => ({ key, value }));
    /**
    * keyValueArray:
    * [
    * { key: "api_url", value: "https://hawaii.usa.gov" },
    * { key: "message", value: "BALLISTIC MISSILE INBOUND." },
    * { key: "is_drill", value: true },
    * ],
    *
    */

    const backToKeyValueObj = keyValueArray.reduce((obj, { key, value }) => ({ ...obj, [key]: value}), {})

    /**
    * backToKeyValueObj:
    * { "api_url": "https://hawaii.usa.gov", "message": "BALLISTIC MISSILE INBOUND. THIS IS NOT A DRILL.", "is_drill": true }
    */
  3. aaronranard created this gist Feb 15, 2018.
    2 changes: 2 additions & 0 deletions key-value-transform.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    const keyValueObj = { "key": "value", "key2": "value2", "key3": "value3" };
    const keyValueArray = Object.entries(keyValueObj).map(([key, value]) => ({ key, value }));