what is immutable

Solutions on MaxInterview for what is immutable by the best coders in the world

showing results for - "what is immutable"
Augustin
14 Jun 2017
1// by negative example here is how to make a javascript immutable
2
3'use strict';
4
5const a = Object.freeze([4, 5, 6]);
6
7// Instead of: a.push(7, 8, 9);
8const b = a.concat(7, 8, 9);
9
10// Instead of: a.pop();
11const c = a.slice(0, -1);
12
13// Instead of: a.unshift(1, 2, 3);
14const d = [1, 2, 3].concat(a);
15
16// Instead of: a.shift();
17const e = a.slice(1);
18
19// Instead of: a.sort(myCompareFunction);
20const f = R.sort(myCompareFunction, a); // R = Ramda
21
22// Instead of: a.reverse();
23const g = R.reverse(a); // R = Ramda