Skip to content

Latest commit

 

History

History
32 lines (24 loc) · 667 Bytes

find-unique-number.md

File metadata and controls

32 lines (24 loc) · 667 Bytes

Description

There is an array with some numbers. All numbers are equal except for one. Try to find it!

findUniq([ 1, 1, 1, 2, 1, 1 ]) === 2
findUniq([ 0, 0, 0.55, 0, 0 ]) === 0.55

It’s guaranteed that array contains 3 or more numbers.

Kata's link: Regex Password Validation

Best Practices

First:

function findUniq(arr) {
  arr.sort((a,b)=>a-b);
  return arr[0]==arr[1]?arr.pop():arr[0]
}

Second:

function findUniq(arr) {
  return +arr.filter( (value) => { return arr.indexOf(value) == arr.lastIndexOf(value) } );
}

My solutions

I didn't resolve it.