@JamesCrowley/

Practice Sandbox

Nodejs

Anything goes

fork
loading
Files
  • index.js
index.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
let userDan = {
name : 'Dan',
email : '[email protected]',
password : 'ABC123'
}
 //Creates a new object, userDAN

function User(nameString, emailString, passwordString) {
     this = {
       this.nameString = name,
       this.emailString = email,
       this.passwordString = password,
     };
  return user here 
  return user;
  }
//This is our class constructor.

let userSara = new User('sara', '[email protected]', '321cba')
console.log(UserSara);

//The "new" keyword denotes a class
//The "this" keyword sets the key to the object
//Creates object automatically - Example:
//function user(name, email, password){
 // let user = {
 //   this.name : name,
 //   this.email : email,
 //   this.password : password
 //}
//return
//}

//callback function
//function addsTwoNumbers(num1, num2) {
 // return num1 + num2;
 
//}

//function calculator(callback, numberOne, numberTwo) {
  // callback = addsTwoNumbers;
  // return callback(numberOne, numberTwo);
//}

//calculator(addsTwoNumbers, 1, 3);

let numsArray = [42, 100, 30, 33];

function mapMethod(array, cb){
  //create a new array
  let newArray = [];
  //create a for loop
  for(let i = 0; i < array.length; i++){
  //save the value returned from a callback
  let updatedValue = cb(array[i]);
  //add that value to the new array
  newArray.push(updatedValue);
  }
//return the new array
return newArray;
}
function addThree(num) {
  return num + 3;
}

mapMethod(numsArray, addThree);

//all of this is happening in the .map method!
//numsArray.map(addThree) will accomplish the same thing as the above method.
node v10.16.0