Skip to content

Instantly share code, notes, and snippets.

@barfi
Last active March 7, 2023 00:31
Show Gist options
  • Select an option

  • Save barfi/fa165dfcfd3ea1ac92a00709551c0af7 to your computer and use it in GitHub Desktop.

Select an option

Save barfi/fa165dfcfd3ea1ac92a00709551c0af7 to your computer and use it in GitHub Desktop.

Revisions

  1. barfi revised this gist Mar 7, 2023. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions rock_paper_scissors.md
    Original file line number Diff line number Diff line change
    @@ -1,18 +1,18 @@
    ```js
    // Case with 3 objects
    const abc = (p1, p2, map = { a:0, c:1, b:2 }) => {
    return ['P1 == P2', 'P1', 'P2'][(map[p1] - map[p2] + 3) % 3]
    return ['DRAW', 'P1', 'P2'][(map[p1] - map[p2] + 3) % 3]
    }
    ```
    ```js
    // Case with 4 objects
    const abcd = (p1, p2, map = { a:0, d:1, c:2, b:3 }) => {
    return ['P1 == P2', 'P1', 'P2'][(map[p1] - map[p2]) % 2 && (4 - ((map[p1] - map[p2] + 4) % 4)) % 3 + 1]
    return ['DRAW', 'P1', 'P2'][(map[p1] - map[p2]) % 2 && (4 - ((map[p1] - map[p2] + 4) % 4)) % 3 + 1]
    }
    ```
    ```js
    // Case with 5 objects
    const abcde = (p1, p2, map = { a:0, e:1, d:2, c:3, b:4 }) => {
    return ['P1 == P2', 'P1', 'P2'][((map[p1] - map[p2] + 5) % 5 - 1) % 2 + 1]
    return ['DRAW', 'P1', 'P2'][((map[p1] - map[p2] + 5) % 5 - 1) % 2 + 1]
    }
    ```
  2. barfi revised this gist Mar 7, 2023. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions rock_paper_scissors.md
    Original file line number Diff line number Diff line change
    @@ -1,18 +1,18 @@
    ```js
    // Case with 3 objects
    const abc = (x, y, map = { a:0, c:1, b:2 }) => {
    return ['P1 == P2', 'P1', 'P2'][(map[x] - map[y] + 3) % 3]
    const abc = (p1, p2, map = { a:0, c:1, b:2 }) => {
    return ['P1 == P2', 'P1', 'P2'][(map[p1] - map[p2] + 3) % 3]
    }
    ```
    ```js
    // Case with 4 objects
    const abcd = (x, y, map = { a:0, d:1, c:2, b:3 }) => {
    return ['P1 == P2', 'P1', 'P2'][(map[x] - map[y]) % 2 && (4 - ((map[x] - map[y] + 4) % 4)) % 3 + 1]
    const abcd = (p1, p2, map = { a:0, d:1, c:2, b:3 }) => {
    return ['P1 == P2', 'P1', 'P2'][(map[p1] - map[p2]) % 2 && (4 - ((map[p1] - map[p2] + 4) % 4)) % 3 + 1]
    }
    ```
    ```js
    // Case with 5 objects
    const abcde = (x, y, map = { a:0, e:1, d:2, c:3, b:4 }) => {
    return ['P1 == P2', 'P1', 'P2'][((map[x] - map[y] + 5) % 5 - 1) % 2 + 1]
    const abcde = (p1, p2, map = { a:0, e:1, d:2, c:3, b:4 }) => {
    return ['P1 == P2', 'P1', 'P2'][((map[p1] - map[p2] + 5) % 5 - 1) % 2 + 1]
    }
    ```
  3. barfi renamed this gist Mar 7, 2023. 1 changed file with 10 additions and 12 deletions.
    22 changes: 10 additions & 12 deletions rock_paper_scissors.js → rock_paper_scissors.md
    Original file line number Diff line number Diff line change
    @@ -1,20 +1,18 @@
    /**
    * Case with 3 objects
    */
    ```js
    // Case with 3 objects
    const abc = (x, y, map = { a:0, c:1, b:2 }) => {
    return ['P1 == P2', 'P1', 'P2'][(map[x] - map[y] + 3) % 3]
    }

    /**
    * Case with 4 objects
    */
    ```
    ```js
    // Case with 4 objects
    const abcd = (x, y, map = { a:0, d:1, c:2, b:3 }) => {
    return ['P1 == P2', 'P1', 'P2'][(map[x] - map[y]) % 2 && (4 - ((map[x] - map[y] + 4) % 4)) % 3 + 1]
    }

    /**
    * Case with 5 objects
    */
    ```
    ```js
    // Case with 5 objects
    const abcde = (x, y, map = { a:0, e:1, d:2, c:3, b:4 }) => {
    return ['P1 == P2', 'P1', 'P2'][((map[x] - map[y] + 5) % 5 - 1) % 2 + 1]
    }
    }
    ```
  4. barfi renamed this gist Mar 7, 2023. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. barfi revised this gist Mar 7, 2023. 1 changed file with 9 additions and 2 deletions.
    11 changes: 9 additions & 2 deletions .js
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,20 @@
    /**
    * Case with 3 objects
    */
    const abc = (x, y, map = {a:0,c:1,b:2}) => {
    const abc = (x, y, map = { a:0, c:1, b:2 }) => {
    return ['P1 == P2', 'P1', 'P2'][(map[x] - map[y] + 3) % 3]
    }

    /**
    * Case with 4 objects
    */
    const abcd = (x, y, map = {a:0,d:1,c:2,b:3}){
    const abcd = (x, y, map = { a:0, d:1, c:2, b:3 }) => {
    return ['P1 == P2', 'P1', 'P2'][(map[x] - map[y]) % 2 && (4 - ((map[x] - map[y] + 4) % 4)) % 3 + 1]
    }

    /**
    * Case with 5 objects
    */
    const abcde = (x, y, map = { a:0, e:1, d:2, c:3, b:4 }) => {
    return ['P1 == P2', 'P1', 'P2'][((map[x] - map[y] + 5) % 5 - 1) % 2 + 1]
    }
  6. barfi revised this gist Mar 7, 2023. 1 changed file with 7 additions and 1 deletion.
    8 changes: 7 additions & 1 deletion .js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,13 @@
    /**
    * Case with 3 objects
    */

    const abc = (x, y, map = {a:0,c:1,b:2}) => {
    return ['P1 == P2', 'P1', 'P2'][(map[x] - map[y] + 3) % 3]
    }

    /**
    * Case with 4 objects
    */
    const abcd = (x, y, map = {a:0,d:1,c:2,b:3}){
    return ['P1 == P2', 'P1', 'P2'][(map[x] - map[y]) % 2 && (4 - ((map[x] - map[y] + 4) % 4)) % 3 + 1]
    }
  7. barfi revised this gist Mar 7, 2023. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions .js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,7 @@
    /**
    * Case with 3 objects
    */

    const abc = (x, y, map = {a:0,c:1,b:2}) => {
    return ['P1 == P2', 'P1', 'P2'][(map[x] - map[y] + 3) % 3]
    }
  8. barfi renamed this gist Mar 7, 2023. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  9. barfi created this gist Mar 7, 2023.
    3 changes: 3 additions & 0 deletions js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    const abc = (x, y, map = {a:0,c:1,b:2}) => {
    return ['P1 == P2', 'P1', 'P2'][(map[x] - map[y] + 3) % 3]
    }