Skip to content

Conversation

Ada-11
Copy link

@Ada-11 Ada-11 commented Oct 30, 2020

Another solution without additional data structures but using objects, with performance O(N).

function isUnique3(str){
let obj = {}
for( let elem of str){
if(obj.hasOwnProperty(elem)) obj[elem]++
else obj[elem]=1
}
for( key in obj){
if (obj[key]=== 1) return true
else return false
}
}

isUnique3('ada') // false
isUnique3("golden") // true

Another solution without additional data structures but using objects, with performance O(N).

function isUnique3(str){
let obj = {}
for( let elem of str){
  if(obj.hasOwnProperty(elem)) obj[elem]++
  else obj[elem]=1
}
for( key in obj){
  if (obj[key]=== 1) return true
  else return false
}
} 

isUnique3('ada') // false
isUnique3("golden") // true
@lhchavez
Copy link
Contributor

dupe of #78

@lhchavez lhchavez closed this Oct 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants