Skip to content

Instantly share code, notes, and snippets.

@zefhemel
Created April 27, 2012 12:19
Show Gist options
  • Save zefhemel/2508739 to your computer and use it in GitHub Desktop.
Save zefhemel/2508739 to your computer and use it in GitHub Desktop.
Author @janjongboom
function isEven(a) {
   a = a.toString().replace(/[^0-9.]/g, "");
   var stack = [];
   var rev = a.split('').reverse();
   for (var ix = 0; ix < rev.length; ix++) {
       if (rev[ix] == ".") stack.push("dot")
       else if (rev[ix] == "1" || rev[ix] == "3" || rev[ix] =="5" || rev[ix] == "7" || rev[ix] == "9")
          stack.push("oneven")
       else
          stack.push('even')
   }
   var wholenumber = stack.splice(stack.indexOf("dot") + 1)
   return wholenumber[0] == "even";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment