forked from mulrooneycasey/CS546FinalProject
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.js
48 lines (38 loc) · 1.55 KB
/
helpers.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
//You can add and export any helper functions you want here. If you aren't using any, then you can just leave this file as is.
function containsSpec(str) { //Helper function to check if a given str contains any special characters; Source - https://bobbyhadz.com/blog/javascript-check-if-string-contains-special-characters#:~:text=To%20check%20if%20a%20string,special%20character%20and%20false%20otherwise.&text=Copied!
const specialChars = /[@#$%^&*()_+=\[\]{}\\|<>\/~]/ //Regular expressions allow storing of patterns of characters for string comparison; The [] allow for the literal to be considered as a range, and appropiate escape characters used for various symbols
return specialChars.test(str); //Test function checks if a regular expression is contained within a given string, returning the respective boolean
}
function containsNum(str){
const nums = /[0123456789]/ //Created using learning from containsSpec
return nums.test(str);
}
function containsSpace(str){
const space = /[\s]/
return space.test(str);
}
function containsPunct(str){
const punct = /[.,!?;:"\-']/
return punct.test(str);
}
function containsAlpha(str){
const alpha1 = /[a-z]/;
const alpha2 = /[A-Z]/;
return alpha1.test(str) || alpha2.test(str);
}
function containsUpper(str){
const alpha = /[A-Z]/;
return alpha.test(str);
}
function compareNumbers(a, b) {
return a.date - b.date;
}
module.exports = {
containsSpec,
containsNum,
containsPunct,
containsAlpha,
containsSpace,
compareNumbers,
containsUpper
};