diff --git a/src/problem1.js b/src/problem1.js index 9a14f2c..c46cb16 100644 --- a/src/problem1.js +++ b/src/problem1.js @@ -1,6 +1,30 @@ function problem1(pobi, crong) { - var answer; - return answer; + if (pobi[1] - pobi[0] !== 1 || crong[1] - crong[0] !== 1) { + return -1; + } + const pobiMax = Math.max(maxValue(String(pobi[0])), maxValue(String(pobi[1]))); + const crongMax = Math.max(maxValue(String(crong[0])), maxValue(String(crong[1]))); + + if(pobiMax > crongMax){ + return 1; + } else if(pobiMax < crongMax){ + return 2; + } else { + return 0; + } + +} + +function maxValue(page){ + let sum = 0; + let mul = 1; + const pageStr = page.split(""); + for(let i of pageStr){ + sum += Number(i); + mul *= Number(i); + } + return Math.max(sum, mul); } + module.exports = problem1; diff --git a/src/problem2.js b/src/problem2.js index cebd07c..31646dd 100644 --- a/src/problem2.js +++ b/src/problem2.js @@ -1,6 +1,14 @@ function problem2(cryptogram) { - var answer; - return answer; + const stack = []; + let secret = cryptogram.split(""); + for( let i = 0; i < secret.length; i++){ + stack.push(secret[i]); + if(stack.length >= 2 && stack[stack.length - 1] === stack[stack.length - 2]){ + stack.pop(); + stack.pop(); + } + } + return stack.join(""); } module.exports = problem2; diff --git a/src/problem3.js b/src/problem3.js index 1baed28..512f39f 100644 --- a/src/problem3.js +++ b/src/problem3.js @@ -1,6 +1,14 @@ function problem3(number) { - var answer; - return answer; + let clap = 0; + for(let i=1; i<=number; i++){ + let str = String(i).split(""); + for(let j of str){ + if(j === "3" || j === "6" || j === "9"){ + clap+=1; + } + } + } + return clap; } module.exports = problem3; diff --git a/src/problem4.js b/src/problem4.js index ee1d3bd..a1f5f3f 100644 --- a/src/problem4.js +++ b/src/problem4.js @@ -1,6 +1,24 @@ function problem4(word) { - var answer; - return answer; + let result = ''; + + for (let i = 0; i < word.length; i++) { + const char = word[i]; + const charCode = char.charCodeAt(0); + + if (charCode >= 65 && charCode <= 90) { + const newCharCode = 90 + 65 - charCode; + result += String.fromCharCode(newCharCode); + } + else if (charCode >= 97 && charCode <= 122) { + const newCharCode = 122 + 97 - charCode; + result += String.fromCharCode(newCharCode); + } + else { + result += char; + } + } + return result; } + module.exports = problem4; diff --git a/src/problem5.js b/src/problem5.js index 9368e87..28ff163 100644 --- a/src/problem5.js +++ b/src/problem5.js @@ -1,5 +1,12 @@ function problem5(money) { - var answer; + const change = [50000, 10000, 5000, 1000, 500, 100, 50, 10, 1]; + let answer = Array(change.length).fill(0); + let i = 0; + while(money !== 0){ + answer[i] = parseInt(money/change[i]); + money = money % change[i]; + i++; + } return answer; } diff --git a/src/problem6.js b/src/problem6.js index 3f842b5..e314aca 100644 --- a/src/problem6.js +++ b/src/problem6.js @@ -1,6 +1,26 @@ function problem6(forms) { - var answer; - return answer; + let errorEmail = []; + + for(let i=0;i score > 0) + .sort(([idA, scoreA], [idB, scoreB]) => { + if (scoreA !== scoreB) { + return scoreB - scoreA; + } + return idA.localeCompare(idB); + }) + .map(([id, _]) => id) + .slice(0, 5); + + return sortedCandidates; } module.exports = problem7;