Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jack Pires #108

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
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
4 changes: 4 additions & 0 deletions src/challenge1.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
// Using the function keyword declare a function called `greet`
// that returns a String "Hi, Ed!"

function greet() {
return "Hi, Ed!"
}
5 changes: 5 additions & 0 deletions src/challenge2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//Declare a `function` called `greet` that has 1 argument called `name` and returns a String `"Hi, <name>!"`

function greet(name) {
return ("Hi, " + name)
}
3 changes: 3 additions & 0 deletions src/challenge3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//Same as Challenge 2 - this time use an arrow function

const greet = name => "Hi, " + name;
10 changes: 10 additions & 0 deletions src/challenge4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#### Requirements
In a markdown or text file called `challenge4.md` or `challenge4.txt`, write an explanation of
- what `First Class` functions are
- how this concept applies in JS.
- what the difference is between declaring a function and calling it
- Bonus: give examples for each explanation

A first class function is a function which is able to be manipulated like any other variable within its programming language. JavaScript has first class functions as they can be passed as parameters or manipulated the same as any other variable within the language.

Declaring a function is the process of defining what parameters a function takes and what commands it executes upon those parameters before ultimately returning a value. Calling a function is the process of passing the required parameters to a function and receiving an output according to the commands it performs. A function may be called many times upon executing a program, however it will likely only have one declaration (perhaps more if optional parameters may be provided and those cause the function to need slightly different commands.)
16 changes: 16 additions & 0 deletions src/challenge5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*#### Requirements
Use class syntax to create a Student class that initializes with a name property and has a method that returns the capitalised name.
*/

class Student {
constructor(name) {
this.name = name
}

capitalisedName() {
return (this.name[0].toUpperCase() + this.name.slice(1))
}
}

let student = new Student("asia")
student.capitalisedName() // "Asia"
64 changes: 64 additions & 0 deletions src/challenge6.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*#### Requirements
I want to be able to encrypt a string using letter-number substitution according to this[table of values](https://gist.github.com/dearshrewdwit/691c71616995ad2430ab309aa9998745)

"E" -> "32"
"d" -> "5"
"Ed" -> "325"
"Hi, Ed!" -> "351078132554"

Use your best judgment with your pair partner.If you want clarification, ask your coach.
*/

//Stores the key-value pairs for encryption.
class Keys {
constructor() {
this._keys = new Array();
}

get keys() {
return (this._keys)
}

//Assigns key-value pairs for encryption
addKey(key_pair) {
this._keys.push([key_pair[0], key_pair.slice(3)]);
}
}

//Converts a character to a number.
function convert(char) {
for (let i = 0; i < keys.keys.length; i++) {
if (char === keys.keys[i][0]) {
return (keys.keys[i][1]);
}
}
}

//Converts a string into the equivalent encrypted form.
function encryptString(string) {
let encrypted_string = ''
for (let i = 0; i < string.length; i++) {
encrypted_string += convert(string[i])
}
return (encrypted_string);
}

//Initialise required packages and set up the keys for parsing.
const keys = new Keys()
const readline = require('readline');
const fs = require('fs');

const rl = readline.createInterface({
input: fs.createReadStream('src\\challenge6.txt')
});

//Listens for events as rl reads the file.
rl.on('line', (line) => {
if (line !== "character, value") {
keys.addKey(line);
}
})
.on('close', function () {
console.log(encryptString("Hi, Ed!"));
})

98 changes: 98 additions & 0 deletions src/challenge6.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
character, value
, 1
a, 2
b, 3
c, 4
d, 5
e, 6
f, 7
g, 8
h, 9
i, 10
j, 11
k, 12
l, 13
m, 14
n, 15
o, 16
p, 17
q, 18
r, 19
s, 20
t, 21
u, 22
v, 23
w, 24
x, 25
y, 26
z, 27
A, 28
B, 29
C, 30
D, 31
E, 32
F, 33
G, 34
H, 35
I, 36
J, 37
K, 38
L, 39
M, 40
N, 41
O, 42
P, 43
Q, 44
R, 45
S, 46
T, 47
U, 48
V, 49
W, 50
X, 51
Y, 52
Z, 53
!, 54
@, 55
£, 56
$, 57
%, 58
^, 59
&, 60
*, 61
(, 62
), 63
-, 64
_, 65
=, 66
+, 67
[, 68
], 69
{, 70
}, 71
;, 72
:, 73
', 74
", 75
\, 76
|, 77
,, 78
., 79
<, 80
>, 81
/, 82
?, 83
`, 84
~, 85
§, 86
±, 87
1, 88
2, 89
3, 90
4, 91
5, 92
6, 93
7, 94
8, 95
9, 96
0, 97