Last active
September 7, 2018 13:16
-
-
Save glutaminefree/9bb00ea7d21db13cb2da45d0d1df185f to your computer and use it in GitHub Desktop.
Iwu skill test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function copyObject(objOrig) { | |
let objCopy = {}; | |
let key = ''; | |
for(key in objOrig) { | |
if (objOrig.hasOwnProperty(key)) { | |
objCopy[key] = typeof objOrig[key] === 'object' ? copyObject(objOrig[key]) : objOrig[key]; | |
} | |
} | |
return objCopy; | |
} | |
function drawRating(vote) { | |
if (vote < 21) { | |
return '★☆☆☆☆'; | |
} | |
if (vote < 41) { | |
return '★★☆☆☆'; | |
} | |
if (vote < 61) { | |
return '★★★☆☆'; | |
} | |
if (vote < 81) { | |
return '★★★★☆'; | |
} | |
return '★★★★★'; | |
} | |
// more dinamic variant, but too complex | |
function drawRating2(vote) { | |
let n = 0; | |
let stars = []; | |
let starsCount = parseInt(vote / 20) + ((vote % 20 > 0) ? 1 : 0); | |
if (starsCount === 0) { | |
starsCount = 1; | |
} | |
for(n = 0; n < starsCount; n++) { | |
stars.push('★'); | |
} | |
while(stars.length < 5) { | |
stars.push('☆'); | |
} | |
return stars.join(''); | |
} | |
function func(s, a, b) { | |
if (s.length === 0) { | |
return -1; | |
} | |
let i = s.length -1; | |
let aIndex = -1; | |
let bIndex = -1; | |
while ((aIndex == -1) && (bIndex == -1) && (i > 0)) { | |
if (s.substring(i, i + 1) == a) { | |
aIndex = i; | |
} | |
if (s.substring(i, i + 1) == b) { | |
bIndex = i; | |
} | |
i--; | |
} | |
if (aIndex != -1) { | |
return bIndex == -1 ? aIndex : Math.max(aIndex, bIndex); | |
} | |
return bIndex != -1 ? bIndex : -1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment