-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
65 lines (55 loc) · 1.2 KB
/
test.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
// var value = 1;
// function foo() {
// console.log(value);
// }
// function bar() {
// var value = 2;
// foo();
// }
// bar();
// /**
// *
// * @param {Object} obj
// */
// function deepClone(obj = {}) {
// if (typeof obj !== "object" || obj == null) {
// return obj;
// }
// let result;
// if (obj instanceof Array) {
// result = [];
// } else {
// result = {};
// }
// for (const key in obj) {
// if (Object.hasOwnProperty.call(obj, key)) {
// result[key] = deepClone(obj[key]);
// }
// }
// return obj;
// }
// Function.prototype.bind = function () {
// const args = new Array.from(arguments);
// const t = args.unshift();
// const self = this;
// return function () {
// return self.apply(t, args);
// };
// };
// Function.prototype.bind = function () {
// const args = Array.from(arguments);
// const t = args.unshift();
// const self = this;
// return function () {
// self.apply(t, args);
// };
// };
function flatter(arr) {
return arr.reduce(
(pre, cur) =>
Array.isArray(cur) ? pre.concat(flatter(cur)) : pre.concat(cur),
[]
);
}
var arr1 = [1, 2, 3, [1, 2, 3, 4, [2, 3, 4]]];
console.log(flatter(arr1));