Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions src/problem1.js
Original file line number Diff line number Diff line change
@@ -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;
12 changes: 10 additions & 2 deletions src/problem2.js
Original file line number Diff line number Diff line change
@@ -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;
12 changes: 10 additions & 2 deletions src/problem3.js
Original file line number Diff line number Diff line change
@@ -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;
22 changes: 20 additions & 2 deletions src/problem4.js
Original file line number Diff line number Diff line change
@@ -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;
9 changes: 8 additions & 1 deletion src/problem5.js
Original file line number Diff line number Diff line change
@@ -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;
}

Expand Down