Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Find the stray number

// You are given an odd-length array of integers, in which all of them are the same, except for one single number.
// Complete the method which accepts such an array, and returns that single different number.
// The input array will always be valid! (odd-length >= 3)

const stray = function (numbers) {
  let number = 0

  numbers.forEach(x => { if(numbers.indexOf(x) < 1) number = x })
  numbers.forEach(x => { if(numbers.indexOf(x) > 1) number = x })

  return number
}

// With love @kouqhar
Source by www.codewars.com #
 
PREVIOUS NEXT
Tagged: #Find #stray #number
ADD COMMENT
Topic
Name
9+9 =