FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
ReoScript/Source/ReoScript/scripts/array.reo at master · unvell/ReoScript · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
unvell
/
ReoScript
Public
Notifications
You must be signed in to change notification settings
Fork
35
Star
109
Code
Issues
4
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
ReoScript
/
Source
/
ReoScript
/
scripts
/
array.reo
Copy path
More file actions
More file actions
Latest commit
History
History
History
113 lines (89 loc) · 2.33 KB
Breadcrumbs
ReoScript
/
Source
/
ReoScript
/
scripts
/
array.reo
Copy path
File metadata and controls
113 lines (89 loc) · 2.33 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*****************************************************************************
*
* ReoScript - .NET Script Language Engine
*
* https://github.com/unvell/ReoScript
*
* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
* KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
* PURPOSE.
*
* This software released under MIT license.
* Copyright (c) 2012-2019 Jingwood, unvell.com, all rights reserved.
*
****************************************************************************/
if (Array != null && Array.prototype != null) {
// compare two arrays
Array.prototype.equals = targetArray => {
if (targetArray == null || this.length != targetArray.length) {
return false;
}
for (var i = 0; i < this.length; i++) {
if (this[i] != targetArray[i]) {
return false;
}
}
return true;
};
// filter array by given predicate lambda function
Array.prototype.where = function(predicate) {
if (predicate == null) {
return null;
}
var result = [];
for (var element in this) {
if (predicate(element)) {
result.push(element);
}
}
return result;
};
// return the first element
Array.prototype.first = function(predicate) {
if (this.length <= 0) return null;
if (predicate == null) {
return this[0];
}
for (var element in this) {
if (predicate(element)) {
return element;
}
}
return null;
};
// return the last element
Array.prototype.last = function() {
if (this.length <= 0) return null;
if (predicate == null) {
return this[this.length - 1];
}
for (var i = this.length - 1; i >= 0; i--) {
var element = this[i];
if (predicate(element)) {
return element;
}
}
return null;
};
Array.prototype.each = function(iterator) {
for (var element in this) {
iterator.call(element);
}
};
Array.prototype.map = function(mapper) {
var arr = new Array(this.length);
for (var i = 0; i < this.length; i++) {
arr[i] = mapper(this[i]);
}
return arr;
};
Array.prototype.reduce = function(callback, initValue) {
var current = initValue == 0 ? null : initValue;
for (var i = 0; i < this.length; i++) {
var element = this[i];
current = callback(current, element, i);
}
return current;
}
}
Back
|
FazBrowse Home
|
New Git URL