Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Find the stray number

const stray = numbers => {
  let number = 0
  
  numbers.forEach(x => numbers.indexOf(x) ? number = x : null)
  return number
}
console.log(stray([17, 17, 3, 17, 17, 17, 17]))
Comment

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
Comment

PREVIOUS NEXT
Code Example
Javascript :: php watermark facile 
Javascript :: react native vector icons not showing 
Javascript :: react native filter list 
Javascript :: how to append data to a field in mongoose model 
Javascript :: get the whole value of a number javascript 
Javascript :: jquery import js file 
Javascript :: status 502 bad api gateway error solution for aws lambda 
Javascript :: js get node index 
Javascript :: Ways to iterate array in js 
Javascript :: lpad javascript 
Javascript :: discord.js 
Javascript :: all &nbsp; to space from string javascript 
Javascript :: redux dispatch no connect 
Javascript :: select element by id 
Javascript :: editting collection in firebase firestore 
Javascript :: js unspecified parameters 
Javascript :: copy text on button click in jquery 
Javascript :: EACCES: permission denied 
Javascript :: merge 2 array of object by key 
Javascript :: sum all values of an array 
Javascript :: jquery validator add method 
Javascript :: js retour à la ligne 
Javascript :: angular new component 
Javascript :: filter array of objects with array of objects 
Javascript :: install react bootstrap 
Javascript :: redux toolkit with redux persist 
Javascript :: react electron boilerplate 
Javascript :: add image to ag-grid with react 
Javascript :: commander js 
Javascript :: vue 3 router alias 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =