1
+ //I pledge my honor that I have abided by the Stevens Honor System - Aparajita Rana
2
+
3
+ const { promises } = require ( "fs" ) ;
4
+
5
+ const questionOne = function questionOne ( arr ) {
6
+ // Implement question 1 here
7
+
8
+ if ( arr == undefined ) {
9
+ return { } ;
10
+ }
11
+ if ( arr . length == 0 ) {
12
+ return { } ;
13
+ }
14
+
15
+ let prime = { } ;
16
+
17
+ for ( let x = 0 ; x < arr . length ; x ++ ) {
18
+ let num = arr [ x ] ;
19
+ let temp = true ;
20
+ //base cases
21
+ if ( num == 0 || num == 1 ) {
22
+ temp = false ;
23
+ }
24
+ //check if divisable by anything -> if it is then not prime ret false
25
+ else {
26
+ for ( let y = 2 ; y <= num / 2 ; y ++ ) {
27
+ if ( num % y == 0 ) {
28
+ temp = false ;
29
+ }
30
+ }
31
+ }
32
+ //set the res into the right place
33
+ prime [ num ] = temp ? true : false ;
34
+ }
35
+ return prime ;
36
+ }
37
+
38
+ const questionTwo = function questionTwo ( arr ) {
39
+ // Implement question 2 here
40
+
41
+ if ( arr . length === 0 || arr == undefined ) {
42
+ return 0 ;
43
+ }
44
+
45
+ let myNumArraySquared = arr . map ( ( x ) => {
46
+ return x * x ;
47
+ } ) ;
48
+
49
+ let sum = myNumArraySquared . reduce ( ( a , b ) => a + b , 0 ) ;
50
+ let temp = Math . sqrt ( Math . pow ( sum , 5 ) ) ;
51
+
52
+ //toFixed returns string -> we want number
53
+ return Number ( temp . toFixed ( 2 ) ) ;
54
+
55
+ }
56
+
57
+ const questionThree = function questionThree ( text ) {
58
+ // Implement question 3 here
59
+ let vals = { consonants : 0 , vowels : 0 , numbers : 0 , spaces : 0 , punctuation : 0 , specialCharacters : 0 }
60
+ if ( text . length <= 0 || text == undefined ) {
61
+ return vals ;
62
+ }
63
+
64
+ // regex format: g -> string i -> ignores case
65
+ var vow = text . match ( / [ a e i o u ] / gi) ;
66
+ vals . vowels = ( vow != null ) ? vow . length : 0 ;
67
+
68
+ var num = text . match ( / [ 0 1 2 3 3 4 5 6 7 8 9 ] / gi) ;
69
+ vals . numbers = ( num != null ) ? num . length : 0 ;
70
+
71
+ vals . spaces = ( text . split ( " " ) . length - 1 ) ;
72
+
73
+ var punc = text . match ( / [ . , ' : ; ! ? ] / gi) ;
74
+ vals . punctuation = ( punc != null ) ? punc . length : 0 ;
75
+
76
+ var spec = text . match ( / [ @ # $ % ^ & * ] / gi) ;
77
+ vals . specialCharacters = ( spec != null ) ? spec . length : 0 ;
78
+
79
+ var cons = text . match ( / [ b c d f g h j k l m n p q r s t v w x z y ] / gi) ;
80
+ vals . consonants = ( cons != null ) ? cons . length : 0 ;
81
+
82
+ return vals ;
83
+ }
84
+
85
+ const questionFour = function questionFour ( num1 , num2 , num3 ) {
86
+ // Implement question 4 here
87
+ if ( num1 < 0 || num2 < 0 || num3 < 0 ) {
88
+ return - 1 ;
89
+ }
90
+
91
+ // Loan Payment (P) = Amount (A) / Discount Factor (D)
92
+ var rate = ( num2 / 100 ) / 12 ;
93
+ var mon = num3 * 12 ;
94
+ var temp = Math . pow ( ( 1 + rate ) , mon ) ;
95
+
96
+ if ( rate === 0 ) {
97
+ var res = num1 / mon ;
98
+ return parseFloat ( res . toFixed ( 2 ) , 10 ) ;
99
+ }
100
+ else {
101
+ var res2 = ( num1 * rate * temp ) / ( temp - 1 ) ;
102
+ return parseFloat ( res2 . toFixed ( 2 ) , 10 ) ;
103
+ }
104
+ }
105
+
106
+ module . exports = {
107
+ firstName : "Aparajita" ,
108
+ lastName : "Rana" ,
109
+ studentId : "10440384" ,
110
+ questionOne,
111
+ questionTwo,
112
+ questionThree,
113
+ questionFour
114
+ } ;
0 commit comments