Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. That's one way to do it

That's one way to do it

Scheduled Pinned Locked Moved The Weird and The Wonderful
comhelp
64 Posts 38 Posters 35 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Jon McKee

    You left out the glorious sister project:

    It is also important to know if a number is odd, so additionally I created this other package @samuelmarina/is-odd

    Spoiler: It's not just function isOdd(x) { return !isEven(x); } :laugh:

    P Offline
    P Offline
    PIEBALDconsult
    wrote on last edited by
    #5

    function isOdd(x) { return isEven(x**-1**); } ? function isOdd(x) { return isEven(**~**x); } ?

    J J 2 Replies Last reply
    0
    • P PIEBALDconsult

      Only works with base-10 ? :-D Surely it would be better written recursively.

      J Offline
      J Offline
      Jon McKee
      wrote on last edited by
      #6

      I... what?! I thought you were joking for a second but there actually is a definition for even and odd in generic bases. In even bases it's the last-digit test - odd is odd, even is even; in odd bases it's a test of the sum of all digits - odd is odd, even is even. That makes complete sense; it's just not something I've ever considered :omg:

      D 1 Reply Last reply
      0
      • P PIEBALDconsult

        function isOdd(x) { return isEven(x**-1**); } ? function isOdd(x) { return isEven(**~**x); } ?

        J Offline
        J Offline
        Jon McKee
        wrote on last edited by
        #7

        Your sanity only wishes those were the case :-D Also that second one is clever.

        1 Reply Last reply
        0
        • K Kent Sharkey

          GitHub - samuelmarina/is-even[^]

          Quote:

          This is a 100% serious project, and it is made to help the community.

          A brief excerpt:

          function isEven(number) {
          if(number === 1) return false;
          else if(number === 2) return true;
          else if(number === 3) return false;
          else if(number === 4) return true;
          else if(number === 5) return false;
          else if(number === 6) return true;
          else if(number === 7) return false;

          They're up to 1,000,001 now. Help them grow! :doh:

          TTFN - Kent

          K Offline
          K Offline
          kalberts
          wrote on last edited by
          #8

          I grew up with classmates named Odd and Even (which are not unusual boy's names around here). There was never any problem keeping them apart.

          1 Reply Last reply
          0
          • K Kent Sharkey

            GitHub - samuelmarina/is-even[^]

            Quote:

            This is a 100% serious project, and it is made to help the community.

            A brief excerpt:

            function isEven(number) {
            if(number === 1) return false;
            else if(number === 2) return true;
            else if(number === 3) return false;
            else if(number === 4) return true;
            else if(number === 5) return false;
            else if(number === 6) return true;
            else if(number === 7) return false;

            They're up to 1,000,001 now. Help them grow! :doh:

            TTFN - Kent

            J Offline
            J Offline
            James Walsh Jr
            wrote on last edited by
            #9

            Oh. My. Word. :sigh:

            1 Reply Last reply
            0
            • K Kent Sharkey

              GitHub - samuelmarina/is-even[^]

              Quote:

              This is a 100% serious project, and it is made to help the community.

              A brief excerpt:

              function isEven(number) {
              if(number === 1) return false;
              else if(number === 2) return true;
              else if(number === 3) return false;
              else if(number === 4) return true;
              else if(number === 5) return false;
              else if(number === 6) return true;
              else if(number === 7) return false;

              They're up to 1,000,001 now. Help them grow! :doh:

              TTFN - Kent

              B Offline
              B Offline
              Brisingr Aerowing
              wrote on last edited by
              #10

              42 MEGABYTES OF JAVASCRIPT?! :omg: :wtf: Someone needs their head checked!

              What do you get when you cross a joke with a rhetorical question? The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism. Do questions with multiple question marks annoy you???

              P P 2 Replies Last reply
              0
              • B Brisingr Aerowing

                42 MEGABYTES OF JAVASCRIPT?! :omg: :wtf: Someone needs their head checked!

                What do you get when you cross a joke with a rhetorical question? The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism. Do questions with multiple question marks annoy you???

                P Offline
                P Offline
                PIEBALDconsult
                wrote on last edited by
                #11

                Maybe they'll add a few icons later.

                1 Reply Last reply
                0
                • B Brisingr Aerowing

                  42 MEGABYTES OF JAVASCRIPT?! :omg: :wtf: Someone needs their head checked!

                  What do you get when you cross a joke with a rhetorical question? The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism. Do questions with multiple question marks annoy you???

                  P Offline
                  P Offline
                  Peter_in_2780
                  wrote on last edited by
                  #12

                  Brisingr Aerowing wrote:

                  42 MEGABYTES OF JAVASCRIPT?!

                  Meh. It'll get lost in the framework(s) downloaded with it.

                  Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012

                  J 1 Reply Last reply
                  0
                  • K Kent Sharkey

                    GitHub - samuelmarina/is-even[^]

                    Quote:

                    This is a 100% serious project, and it is made to help the community.

                    A brief excerpt:

                    function isEven(number) {
                    if(number === 1) return false;
                    else if(number === 2) return true;
                    else if(number === 3) return false;
                    else if(number === 4) return true;
                    else if(number === 5) return false;
                    else if(number === 6) return true;
                    else if(number === 7) return false;

                    They're up to 1,000,001 now. Help them grow! :doh:

                    TTFN - Kent

                    C Offline
                    C Offline
                    Chris Nic
                    wrote on last edited by
                    #13

                    They have forgotten about negative numbers :(

                    B 1 Reply Last reply
                    0
                    • C Chris Nic

                      They have forgotten about negative numbers :(

                      B Offline
                      B Offline
                      Bernhard Hiller
                      wrote on last edited by
                      #14

                      And 0. Is 0 even or odd? How can we know when that code is lacking the answer to this most important question?

                      Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!

                      D 1 Reply Last reply
                      0
                      • K Kent Sharkey

                        GitHub - samuelmarina/is-even[^]

                        Quote:

                        This is a 100% serious project, and it is made to help the community.

                        A brief excerpt:

                        function isEven(number) {
                        if(number === 1) return false;
                        else if(number === 2) return true;
                        else if(number === 3) return false;
                        else if(number === 4) return true;
                        else if(number === 5) return false;
                        else if(number === 6) return true;
                        else if(number === 7) return false;

                        They're up to 1,000,001 now. Help them grow! :doh:

                        TTFN - Kent

                        M Offline
                        M Offline
                        Member 9167057
                        wrote on last edited by
                        #15

                        Well, if you troll, then you might just as well do it right, walking the walk way to the end.

                        K 1 Reply Last reply
                        0
                        • P Peter_in_2780

                          Brisingr Aerowing wrote:

                          42 MEGABYTES OF JAVASCRIPT?!

                          Meh. It'll get lost in the framework(s) downloaded with it.

                          Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012

                          J Offline
                          J Offline
                          JohaViss61
                          wrote on last edited by
                          #16

                          It's at 94.8MB now

                          M 1 Reply Last reply
                          0
                          • K Kent Sharkey

                            GitHub - samuelmarina/is-even[^]

                            Quote:

                            This is a 100% serious project, and it is made to help the community.

                            A brief excerpt:

                            function isEven(number) {
                            if(number === 1) return false;
                            else if(number === 2) return true;
                            else if(number === 3) return false;
                            else if(number === 4) return true;
                            else if(number === 5) return false;
                            else if(number === 6) return true;
                            else if(number === 7) return false;

                            They're up to 1,000,001 now. Help them grow! :doh:

                            TTFN - Kent

                            K Offline
                            K Offline
                            KateAshman
                            wrote on last edited by
                            #17

                            In all seriousness, it also tells if a written number is even or odd. I've seen worse.

                            Richard DeemingR 1 Reply Last reply
                            0
                            • K KateAshman

                              In all seriousness, it also tells if a written number is even or odd. I've seen worse.

                              Richard DeemingR Offline
                              Richard DeemingR Offline
                              Richard Deeming
                              wrote on last edited by
                              #18

                              That just means the package is doing too much. Converting words to numbers should be separated out into its own package, since it's nothing to do with the purpose of the is-even package. :-D


                              "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                              "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                              1 Reply Last reply
                              0
                              • K Kent Sharkey

                                GitHub - samuelmarina/is-even[^]

                                Quote:

                                This is a 100% serious project, and it is made to help the community.

                                A brief excerpt:

                                function isEven(number) {
                                if(number === 1) return false;
                                else if(number === 2) return true;
                                else if(number === 3) return false;
                                else if(number === 4) return true;
                                else if(number === 5) return false;
                                else if(number === 6) return true;
                                else if(number === 7) return false;

                                They're up to 1,000,001 now. Help them grow! :doh:

                                TTFN - Kent

                                P Offline
                                P Offline
                                Peter Kelley 2021
                                wrote on last edited by
                                #19

                                I'm sure this project is a gag! (and I'm snickering!) Has anyone yet suggested porting this to some cloud-native database of the even numbers? :)

                                Richard DeemingR 1 Reply Last reply
                                0
                                • K Kent Sharkey

                                  GitHub - samuelmarina/is-even[^]

                                  Quote:

                                  This is a 100% serious project, and it is made to help the community.

                                  A brief excerpt:

                                  function isEven(number) {
                                  if(number === 1) return false;
                                  else if(number === 2) return true;
                                  else if(number === 3) return false;
                                  else if(number === 4) return true;
                                  else if(number === 5) return false;
                                  else if(number === 6) return true;
                                  else if(number === 7) return false;

                                  They're up to 1,000,001 now. Help them grow! :doh:

                                  TTFN - Kent

                                  S Offline
                                  S Offline
                                  Slow Eddie
                                  wrote on last edited by
                                  #20

                                  What? :confused: I am probably dumb, or inexperienced, or both, but I see no practical use for this.:confused:

                                  Zaphod

                                  1 Reply Last reply
                                  0
                                  • K Kent Sharkey

                                    GitHub - samuelmarina/is-even[^]

                                    Quote:

                                    This is a 100% serious project, and it is made to help the community.

                                    A brief excerpt:

                                    function isEven(number) {
                                    if(number === 1) return false;
                                    else if(number === 2) return true;
                                    else if(number === 3) return false;
                                    else if(number === 4) return true;
                                    else if(number === 5) return false;
                                    else if(number === 6) return true;
                                    else if(number === 7) return false;

                                    They're up to 1,000,001 now. Help them grow! :doh:

                                    TTFN - Kent

                                    S Offline
                                    S Offline
                                    Slow Eddie
                                    wrote on last edited by
                                    #21

                                    What? :confused: I am probably dumb, or inexperienced, or both, but I see no practical use for this.:confused:

                                    1 Reply Last reply
                                    0
                                    • P Peter Kelley 2021

                                      I'm sure this project is a gag! (and I'm snickering!) Has anyone yet suggested porting this to some cloud-native database of the even numbers? :)

                                      Richard DeemingR Offline
                                      Richard DeemingR Offline
                                      Richard Deeming
                                      wrote on last edited by
                                      #22

                                      Feel free to suggest it[^]. :laugh:


                                      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                                      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                                      1 Reply Last reply
                                      0
                                      • K Kent Sharkey

                                        GitHub - samuelmarina/is-even[^]

                                        Quote:

                                        This is a 100% serious project, and it is made to help the community.

                                        A brief excerpt:

                                        function isEven(number) {
                                        if(number === 1) return false;
                                        else if(number === 2) return true;
                                        else if(number === 3) return false;
                                        else if(number === 4) return true;
                                        else if(number === 5) return false;
                                        else if(number === 6) return true;
                                        else if(number === 7) return false;

                                        They're up to 1,000,001 now. Help them grow! :doh:

                                        TTFN - Kent

                                        E Offline
                                        E Offline
                                        englebart
                                        wrote on last edited by
                                        #23

                                        Thanks for sharing this… I was looking for a way to stripe my html tables!

                                        1 Reply Last reply
                                        0
                                        • K Kent Sharkey

                                          GitHub - samuelmarina/is-even[^]

                                          Quote:

                                          This is a 100% serious project, and it is made to help the community.

                                          A brief excerpt:

                                          function isEven(number) {
                                          if(number === 1) return false;
                                          else if(number === 2) return true;
                                          else if(number === 3) return false;
                                          else if(number === 4) return true;
                                          else if(number === 5) return false;
                                          else if(number === 6) return true;
                                          else if(number === 7) return false;

                                          They're up to 1,000,001 now. Help them grow! :doh:

                                          TTFN - Kent

                                          A Offline
                                          A Offline
                                          atverweij
                                          wrote on last edited by
                                          #24

                                          That can be done better with a recursive function:

                                          function IsEven(number) {
                                          if (number === 1 return false;
                                          elseif (number === 2) return true;
                                          else return IsEven(number - 2);
                                          }

                                          Now it does all positive numbers :laugh: EDIT: because I get serious reactions on this code The code above is how NOT to do it - it's satire.

                                          D B B K 4 Replies Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups