Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d70aafd

Browse files
committed
challenges completed
1 parent c73b6b1 commit d70aafd

File tree

4 files changed

+52
-5
lines changed

4 files changed

+52
-5
lines changed

Week3/challenges/1-sum-entries.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ Once you have found those numbers, multiply the numbers and store the result of
99

1010
const list = [1721, 979, 366, 299, 675, 1456];
1111
let result;
12-
12+
list.forEach(item => {
13+
let i = list.indexOf(item) + 1;
14+
for(i ; i<list.length-1; i++) {
15+
if(list[i] + item === 2020) {
16+
result = list[i] * item;
17+
}
18+
}})
1319
// Write your code here
1420

1521

Week3/challenges/2-sum-three-entries.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@ Once you have found those numbers, multiply the numbers and store the result of
99

1010
const list = [1721, 979, 366, 299, 675, 1456];
1111
let result;
12-
12+
list.forEach(item => {
13+
let i = list.indexOf(item) + 1;
14+
let j = list.indexOf(item) + 2;
15+
for(j ; j<list.length-1; j++) {
16+
if(list[i]+list[j]+item === 2020) {
17+
result = list[i] * list[j] * item;
18+
}
19+
}})
1320
// Write your code here
1421

1522

Week3/challenges/3-password-validation.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,21 @@ const passwordList = [
2020
{ times: '1-3', letter: 'a', password: 'abcde'},
2121
{ times: '1-3', letter: 'b', password: 'cdefg'},
2222
{ times: '2-9', letter: 'c', password: 'ccccccccc'}
23-
];
23+
];
24+
25+
passwordList.forEach(item => {
26+
const min = Number(item.times[0]);
27+
const max = Number(item.times[2]);
28+
const letter = item.letter;
29+
const password = item.password.split('');
30+
let frequency = 0;
31+
password.forEach(item => {
32+
if(item === letter){
33+
frequency += 1;
34+
}
35+
})
36+
let validation = '';
37+
frequency >= min && frequency <= max ? validation = 'VALID' : validation = 'INVALID'
38+
console.log(`'${item.password}' is ${validation} ${letter} is present ${frequency} times and should have been present at least ${min} and at most ${max} times `)
39+
40+
})

Week3/challenges/4-bank-account.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,28 @@ const bankAccount = {
2727
],
2828
};
2929

30+
const makeTransaction = (amount, onSuccess, onFail, reason) => {
31+
if(amount > bankAccount.currentBalance){
32+
onFail();
33+
}else {
34+
onSuccess();
35+
currentTransaction = {
36+
prevAmount:0,
37+
newAmount:0,
38+
reason: "",
39+
}
40+
currentTransaction.prevAmount = bankAccount.currentBalance;
41+
bankAccount.currentBalance -= amount;
42+
currentTransaction.newAmount = bankAccount.currentBalance;
43+
currentTransaction.reason = reason;
44+
bankAccount.transactions.push(currentTransaction);
45+
}
46+
};
3047
const donateMoney = (amount, onSuccess, onFail) => {
31-
// TODO complete this function
48+
makeTransaction(amount, onSuccess, onFail, 'Donation');
3249
};
3350
const payRent = (amount, onSuccess, onFail) => {
34-
// TODO complete this function
51+
makeTransaction(amount, onSuccess, onFail, 'Rent')
3552
};
3653

3754
/**

0 commit comments

Comments
 (0)