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 30 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.
  • A atverweij

    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 Offline
    D Offline
    dandy72
    wrote on last edited by
    #25

    Points for being clever. Sadly, someone would still use it...

    A 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
      MarkTJohnson
      wrote on last edited by
      #26

      I'm trying to guess what certain CPers would do if they were confronted with this person. JSOP - bullet in the guy's head to put both the guy and everyone else out of their misery. honey the codewitch - After she quit twitching, she'd write a parser to optimize the code. OriginalGriff - figures out how to turn it into a CCC clue Nagy - just wanders off, asking where the gin is. Me - I'd tell him to turn it all into a switch statement.

      I’ve given up trying to be calm. However, I am open to feeling slightly less agitated.

      W D 2 Replies 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
        Kirk 10389821
        wrote on last edited by
        #27

        You know... It's 2021, and the IRONY flows freely in all things... I expected to see a macro (written in JavaScript), that writes the javascript file: for (x..) if x % 1 == 0 write "if (number == " + x +") return false;" else write "if (number == " + x +") return true;" == And to see him asking people to crowd source running that file, to help him out! == Next question... Where is his test harness... Or is he caught in an infinite loop?

        1 Reply Last reply
        0
        • D dandy72

          Points for being clever. Sadly, someone would still use it...

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

          If someone really uses it, he or she deserves it ;P

          D 1 Reply Last reply
          0
          • M MarkTJohnson

            I'm trying to guess what certain CPers would do if they were confronted with this person. JSOP - bullet in the guy's head to put both the guy and everyone else out of their misery. honey the codewitch - After she quit twitching, she'd write a parser to optimize the code. OriginalGriff - figures out how to turn it into a CCC clue Nagy - just wanders off, asking where the gin is. Me - I'd tell him to turn it all into a switch statement.

            I’ve given up trying to be calm. However, I am open to feeling slightly less agitated.

            W Offline
            W Offline
            wapiti64
            wrote on last edited by
            #29

            I'd side with JSOP, after I made them delete everything.

            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
              John Wellbelove
              wrote on last edited by
              #30

              They've missed a whole set of entries for those that speak British style English. American: Thirty-Two Thousand One Hundred Twelve British: Thirty-Two Thousand One Hundred And Twelve I'd better get editing...

              R M 2 Replies Last reply
              0
              • A atverweij

                If someone really uses it, he or she deserves it ;P

                D Offline
                D Offline
                dandy72
                wrote on last edited by
                #31

                Sometimes the best thing you can do is let others hang themselves. Figuratively speaking. :~

                1 Reply Last reply
                0
                • J John Wellbelove

                  They've missed a whole set of entries for those that speak British style English. American: Thirty-Two Thousand One Hundred Twelve British: Thirty-Two Thousand One Hundred And Twelve I'd better get editing...

                  R Offline
                  R Offline
                  Richard Deeming
                  wrote on last edited by
                  #32

                  Someone's already beaten you to that suggestion: [Feature Request] Support for British English "and" · Issue #85 · samuelmarina/is-even · GitHub[^] :-D


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

                  N 1 Reply Last reply
                  0
                  • A atverweij

                    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.

                    B Offline
                    B Offline
                    BruceCarson
                    wrote on last edited by
                    #33

                    No...only positive integers. Since this is JS, some jerk could pass a float in and get your recursive function to march off the negative end of the numbers.

                    A 1 Reply Last reply
                    0
                    • B BruceCarson

                      No...only positive integers. Since this is JS, some jerk could pass a float in and get your recursive function to march off the negative end of the numbers.

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

                      Hmmm, you are right. The the improved improved version.

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

                      Now it does negatives too ;P EDIT: because I get serious reactions on this code The code above is how NOT to do it - it's satire.

                      B K 2 Replies Last reply
                      0
                      • J John Wellbelove

                        They've missed a whole set of entries for those that speak British style English. American: Thirty-Two Thousand One Hundred Twelve British: Thirty-Two Thousand One Hundred And Twelve I'd better get editing...

                        M Offline
                        M Offline
                        MarkTJohnson
                        wrote on last edited by
                        #35

                        The AND denotes the decimal or fractional portion of the number. So Brits in the example above, Twelve whats?

                        I’ve given up trying to be calm. However, I am open to feeling slightly less agitated.

                        R J 2 Replies Last reply
                        0
                        • A atverweij

                          Hmmm, you are right. The the improved improved version.

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

                          Now it does negatives too ;P EDIT: because I get serious reactions on this code The code above is how NOT to do it - it's satire.

                          B Offline
                          B Offline
                          BruceCarson
                          wrote on last edited by
                          #36

                          And now this line of code is used: IsEven (4.2); It'll bounce around 0 until the heat death of the universe.

                          A 1 Reply Last reply
                          0
                          • A atverweij

                            Hmmm, you are right. The the improved improved version.

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

                            Now it does negatives too ;P EDIT: because I get serious reactions on this code The code above is how NOT to do it - it's satire.

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

                            Why are all the 'else's there? Do they improve code generation?

                            A 1 Reply Last reply
                            0
                            • M MarkTJohnson

                              The AND denotes the decimal or fractional portion of the number. So Brits in the example above, Twelve whats?

                              I’ve given up trying to be calm. However, I am open to feeling slightly less agitated.

                              R Offline
                              R Offline
                              Richard Deeming
                              wrote on last edited by
                              #38

                              Not in British English (or just "English", as it's known). :) "One hundred and twelve" === 112, not 100.12.


                              "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
                              • P PIEBALDconsult

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

                                J Offline
                                J Offline
                                jsc42
                                wrote on last edited by
                                #39

                                PIEBALDconsult wrote:

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

                                The sad thing is that that wouldn't work when testing against '1' as that would be testing to see if 0 was even and their isEven does not have a test for 0.

                                1 Reply Last reply
                                0
                                • M MarkTJohnson

                                  The AND denotes the decimal or fractional portion of the number. So Brits in the example above, Twelve whats?

                                  I’ve given up trying to be calm. However, I am open to feeling slightly less agitated.

                                  J Offline
                                  J Offline
                                  John Wellbelove
                                  wrote on last edited by
                                  #40

                                  The British English convention is to put an 'and' between any hundreds and non-zero tens/units and 'point' to indicate the fraction part. Therefore 123,456.789 is... "One hundred and twenty three thousand, four hundred and fifty six point seven, eight, nine"

                                  1 Reply Last reply
                                  0
                                  • B Bernhard Hiller

                                    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 Offline
                                    D Offline
                                    Daniel Pfeffer
                                    wrote on last edited by
                                    #41

                                    doesn't it throw an exception? :-\

                                    Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.

                                    1 Reply Last reply
                                    0
                                    • M MarkTJohnson

                                      I'm trying to guess what certain CPers would do if they were confronted with this person. JSOP - bullet in the guy's head to put both the guy and everyone else out of their misery. honey the codewitch - After she quit twitching, she'd write a parser to optimize the code. OriginalGriff - figures out how to turn it into a CCC clue Nagy - just wanders off, asking where the gin is. Me - I'd tell him to turn it all into a switch statement.

                                      I’ve given up trying to be calm. However, I am open to feeling slightly less agitated.

                                      D Offline
                                      D Offline
                                      Daniel Pfeffer
                                      wrote on last edited by
                                      #42

                                      Me: Have Security dress the guy in a hazmat suit, and escort him out of the building. I'd then cordon off the area and decontaminate everything he touched on his visit - in an autoclave, by choice. This level of stupidity leaves traces wherever it goes.

                                      Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.

                                      J 1 Reply Last reply
                                      0
                                      • R Richard Deeming

                                        Someone's already beaten you to that suggestion: [Feature Request] Support for British English "and" · Issue #85 · samuelmarina/is-even · GitHub[^] :-D


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

                                        N Offline
                                        N Offline
                                        Nelek
                                        wrote on last edited by
                                        #43

                                        Now the question is... Is the one with that request trolling him? Or does he really needs it for his usage?

                                        M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.

                                        R K 2 Replies Last reply
                                        0
                                        • N Nelek

                                          Now the question is... Is the one with that request trolling him? Or does he really needs it for his usage?

                                          M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.

                                          R Offline
                                          R Offline
                                          Richard Deeming
                                          wrote on last edited by
                                          #44

                                          Well, my comment on that issue requesting support for the Yan tan tethera[^] counting system was perfectly legitimate. :laugh:


                                          "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
                                          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