-
Notifications
You must be signed in to change notification settings - Fork 0
/
09-06-2022.js
52 lines (28 loc) · 1.4 KB
/
09-06-2022.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* 7 Kyu - The Coupon Code
Story
Your online store likes to give out coupons for special occasions. Some customers try to cheat the system by entering invalid codes or using expired coupons.
Task
Your mission:
Write a function called checkCoupon which verifies that a coupon code is valid and not expired.
A coupon is no more valid on the day AFTER the expiration date. All dates will be passed as strings in this format: "MONTH DATE, YEAR".
Examples:
checkCoupon("123", "123", "July 9, 2015", "July 9, 2015") === true
checkCoupon("123", "123", "July 9, 2015", "July 2, 2015") === false
*/
//SOLUTION
function checkCoupon(enteredCode, correctCode, currentDate, expirationDate){
return enteredCode === correctCode && Date.parse(expirationDate) >= Date.parse(currentDate)
}
/* 6 Kyu - Replace With Alphabet Position
Welcome.
In this kata you are required to, given a string, replace every letter with its position in the alphabet.
If anything in the text isn't a letter, ignore it and don't return it.
"a" = 1, "b" = 2, etc.
Example
alphabetPosition("The sunset sets at twelve o' clock.")
Should return "20 8 5 19 21 14 19 5 20 19 5 20 19 1 20 20 23 5 12 22 5 15 3 12 15 3 11" ( as a string )
*/
//SOLUTION
function alphabetPosition(text) {
return text.split('').filter(x => x.toUpperCase() != x.toLowerCase()).map((y,i) => y.toLowerCase()).map((j,i) => j.charCodeAt(0) - 96).join(' ')
}