-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvalue-ref-mutation.js
62 lines (41 loc) · 1.19 KB
/
value-ref-mutation.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
const four = 4
const boolExample = true
const stringExample = 'test'
const arrayExample = []
const objectExample = {firstName: 'Zach'}
objectExample.lastName = 'Mays'
const newObject = {...objectExample, lastName: 'Mays'}
function addTwo(number) {
return number + 2
}
const six = addTwo(four)
// console.log(four, six)
// -----------------
const emptyTodos = []
function addTodo(items, newTodoText) {
const newTodo = {name: newTodoText}
return [...items, newTodo]
}
const updatedTodos = addTodo(emptyTodos, 'learn to code')
// console.log(emptyTodos, updatedTodos)
// const numbers = [1, 3, 6, 9]
// const numbersPlusTwo = numbers.map(n => n + 2)
// console.log(numbers, numbersPlusTwo)
let numbers = []
for(let i = 1; i <= 100; i++) {
numbers.push(i)
}
const evenNumbers = numbers.filter(n => n % 2 === 0)
const oddNumbers = numbers.filter(n => n % 2 !== 0)
console.log(evenNumbers)
console.log(oddNumbers)
// for(let i = 0; i < numbers.length; i++) {
// numbers[i] = numbers[i] + 2
// }
// numbers.forEach((n, i) => {
// numbers[i] = n + 2
// })
// numbers.forEach(function(n) {return n + 2})
// numbers.forEach(addTwo)
// const numbersAddedByTwo
// const moreNumbers = [...numbers, 14]