Skip to content

Instantly share code, notes, and snippets.

@jonopens
Last active March 26, 2018 17:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonopens/99cd13064477844a0be2e6a8af85f8db to your computer and use it in GitHub Desktop.
Save jonopens/99cd13064477844a0be2e6a8af85f8db to your computer and use it in GitHub Desktop.
Codility Challenge for EPAM: review
function solution(S) {
let total = 0;
for(var i = 0; i < S.length; i++){
for(var c = S.length; c > i; c--){
total += uniScore(S.slice(i, c))
}
}
return total
}
function uniScore(string){
let score = 0;
for(var i = 0; i < string.length; i++){
let count = 0
for(var c = 0; c < string.length; c++){
if(string[i] === string[c]){
count++
}
}
if(count === 1){
score++
}
}
return score;
}
@jonopens
Copy link
Author

Changes:

  • removed substringer function
  • moved loop directly into solution function
  • contains only ~60% as much code overall

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment