SHARE
TWEET

Untitled

a guest Jul 17th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. * Finds element without a pair in an unsorted array of integers.
  3. * @param {array} A
  4. * @param {int} Element without a pair
  5. */
  6.  
  7. // Brute-force solution (55% on codility)
  8. function solution(A) {
  9.   for (let digit of A) {
  10.     if(A.indexOf(digit) === A.lastIndexOf(digit)) {
  11.       return digit;
  12.     }
  13.   }
  14. };
  15.  
  16. // Elegant but hard to understand solution using Bitwise XOR operator (100% on codility)
  17. function solution(A) {
  18.   let result = 0;
  19.  
  20.   for (let element of N) {
  21.     result ^= element;
  22.   }
  23.  
  24.   return result;
  25. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top