Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Junming
jio
Commits
94fc1a5f
Commit
94fc1a5f
authored
Nov 27, 2014
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
No need to duplicate the algorithm.
parent
11204f91
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
47 deletions
+28
-47
src/queries/core/tool.js
src/queries/core/tool.js
+28
-47
No files found.
src/queries/core/tool.js
View file @
94fc1a5f
...
@@ -52,56 +52,37 @@ function metadataValueToStringArray(value) {
...
@@ -52,56 +52,37 @@ function metadataValueToStringArray(value) {
* @return {Function} The sort function
* @return {Function} The sort function
*/
*/
function
sortFunction
(
key
,
way
)
{
function
sortFunction
(
key
,
way
)
{
var
result
;
if
(
way
===
'
descending
'
)
{
if
(
way
===
'
descending
'
)
{
return
function
(
a
,
b
)
{
result
=
1
;
// this comparison is 5 times faster than json comparison
}
else
if
(
way
===
'
ascending
'
)
{
var
i
,
l
;
result
=
-
1
;
a
=
metadataValueToStringArray
(
a
[
key
])
||
[];
}
else
{
b
=
metadataValueToStringArray
(
b
[
key
])
||
[];
throw
new
TypeError
(
"
Query.sortFunction():
"
+
l
=
a
.
length
>
b
.
length
?
a
.
length
:
b
.
length
;
"
Argument 2 must be 'ascending' or 'descending'
"
);
for
(
i
=
0
;
i
<
l
;
i
+=
1
)
{
}
if
(
a
[
i
]
===
undefined
)
{
return
function
(
a
,
b
)
{
return
1
;
// this comparison is 5 times faster than json comparison
}
var
i
,
l
;
if
(
b
[
i
]
===
undefined
)
{
a
=
metadataValueToStringArray
(
a
[
key
])
||
[];
return
-
1
;
b
=
metadataValueToStringArray
(
b
[
key
])
||
[];
}
l
=
a
.
length
>
b
.
length
?
a
.
length
:
b
.
length
;
if
(
a
[
i
]
>
b
[
i
])
{
for
(
i
=
0
;
i
<
l
;
i
+=
1
)
{
return
-
1
;
if
(
a
[
i
]
===
undefined
)
{
}
return
result
;
if
(
a
[
i
]
<
b
[
i
])
{
return
1
;
}
}
}
return
0
;
if
(
b
[
i
]
===
undefined
)
{
};
return
-
result
;
}
if
(
way
===
'
ascending
'
)
{
return
function
(
a
,
b
)
{
// this comparison is 5 times faster than json comparison
var
i
,
l
;
a
=
metadataValueToStringArray
(
a
[
key
])
||
[];
b
=
metadataValueToStringArray
(
b
[
key
])
||
[];
l
=
a
.
length
>
b
.
length
?
a
.
length
:
b
.
length
;
for
(
i
=
0
;
i
<
l
;
i
+=
1
)
{
if
(
a
[
i
]
===
undefined
)
{
return
-
1
;
}
if
(
b
[
i
]
===
undefined
)
{
return
1
;
}
if
(
a
[
i
]
>
b
[
i
])
{
return
1
;
}
if
(
a
[
i
]
<
b
[
i
])
{
return
-
1
;
}
}
}
return
0
;
if
(
a
[
i
]
>
b
[
i
])
{
};
return
-
result
;
}
}
throw
new
TypeError
(
"
Query.sortFunction():
"
+
if
(
a
[
i
]
<
b
[
i
])
{
"
Argument 2 must be 'ascending' or 'descending'
"
);
return
result
;
}
}
return
0
;
};
}
}
/**
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment