8 kyu

Exclusive "or" (xor) Logical Operator

14,015 of 46,163donaldsebleung

Description:

Exclusive "or" (xor) Logical Operator

Overview

In some scripting languages like PHP, there exists a logical operator (e.g. &&, ||, and, or, etc.) called the "Exclusive Or" (hence the name of this Kata). The exclusive or evaluates two booleans. It then returns true if exactly one of the two expressions are true, false otherwise. For example:

false xor false == false // since both are false
true xor false == true // exactly one of the two expressions are true
false xor true == true // exactly one of the two expressions are true
true xor true == false // Both are true.  "xor" only returns true if EXACTLY one of the two expressions evaluate to true.

Task

Since we cannot define keywords in Javascript (well, at least I don't know how to do it), your task is to define a function xor(a, b) where a and b are the two expressions to be evaluated. Your xor function should have the behaviour described above, returning true if exactly one of the two expressions evaluate to true, false otherwise.

Fundamentals

Stats:

CreatedMar 29, 2016
PublishedMar 29, 2016
Warriors Trained59368
Total Skips4585
Total Code Submissions82538
Total Times Completed46163
JavaScript Completions14015
Ruby Completions1237
Haskell Completions603
Python Completions13129
Java Completions5846
CoffeeScript Completions65
TypeScript Completions1020
Clojure Completions449
C# Completions2486
C++ Completions4949
C Completions2021
NASM Completions134
Go Completions2497
CFML Completions41
Scala Completions77
Lua Completions73
Groovy Completions25
Dart Completions124
Total Stars267
% of votes with a positive feedback rating89% of 3956
Total "Very Satisfied" Votes3218
Total "Somewhat Satisfied" Votes621
Total "Not Satisfied" Votes117
Total Rank Assessments9
Average Assessed Rank
7 kyu
Highest Assessed Rank
7 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • donaldsebleung Avatar
  • Javatlacati Avatar
  • bkaes Avatar
  • GiacomoSorbi Avatar
  • raulbc777 Avatar
  • Anarki Avatar
  • Dentzil Avatar
  • user5036852 Avatar
  • JohanWiltink Avatar
  • lilsweetcaligula Avatar
  • Blind4Basics Avatar
  • Voile Avatar
  • Souzooka Avatar
  • kroppt Avatar
  • bdw429s Avatar
  • monadius Avatar
  • hobovsky Avatar
  • trashy_incel Avatar
  • user8436785 Avatar
  • FranzMartyn Avatar
  • KayleighWasTaken Avatar
  • metatable Avatar
  • Tester_blck Avatar
Ad