Skip to content

Instantly share code, notes, and snippets.

Created August 8, 2016 05:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/bfff6543377d436381b569ca6be44fe5 to your computer and use it in GitHub Desktop.
Save anonymous/bfff6543377d436381b569ca6be44fe5 to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/yamuju
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
;(function(){
function concatReorderedArray(arr, arr2){
var start = new Date().getTime() ;
if( typeof arr === 'undefined' || arr.length < 1 ) {
console.warn('First array is empty or doesn\'t not exist.')
return false ;
}
if( typeof arr2 === 'undefined' || arr2.length < 1 ) {
console.warn('Second array is empty or doesn\'t not exist.')
return false ;
}
Array.prototype.append = function( array ) {
for( var i = 0, len = array.length; i < len; i++) {
if(typeof array[i] !== 'undefined'){
this.push(array[i]) ;
}
}
}
arr.append(arr2) ;
arr = arr.sort( function( item, item2 ) {
if (item < item2) {
return -1;
}
if (item > item2) {
return 1;
}
return 0;
} ) ;
var end = new Date().getTime() ;
var time = end - start;
console.log(arr);
console.log( 'Array size: ' + arr.length) ;
console.log( 'Execution time: ' + time + 'ms', start, end );
}
function shuffle ( len, range ) {
var arr = [];
for( var i = 0; i < len; i++ ) {
arr.push( Math.floor( ( Math.random() * range ) ) ) ;
}
return arr;
}
concatReorderedArray( shuffle( 50000, 50000000 ), shuffle( 899966, 280000000 ) )
})();
</script>
<script id="jsbin-source-javascript" type="text/javascript">;(function(){
function concatReorderedArray(arr, arr2){
var start = new Date().getTime() ;
if( typeof arr === 'undefined' || arr.length < 1 ) {
console.warn('First array is empty or doesn\'t not exist.')
return false ;
}
if( typeof arr2 === 'undefined' || arr2.length < 1 ) {
console.warn('Second array is empty or doesn\'t not exist.')
return false ;
}
Array.prototype.append = function( array ) {
for( var i = 0, len = array.length; i < len; i++) {
if(typeof array[i] !== 'undefined'){
this.push(array[i]) ;
}
}
}
arr.append(arr2) ;
arr = arr.sort( function( item, item2 ) {
if (item < item2) {
return -1;
}
if (item > item2) {
return 1;
}
return 0;
} ) ;
var end = new Date().getTime() ;
var time = end - start;
console.log(arr);
console.log( 'Array size: ' + arr.length) ;
console.log( 'Execution time: ' + time + 'ms', start, end );
}
function shuffle ( len, range ) {
var arr = [];
for( var i = 0; i < len; i++ ) {
arr.push( Math.floor( ( Math.random() * range ) ) ) ;
}
return arr;
}
concatReorderedArray( shuffle( 50000, 50000000 ), shuffle( 899966, 280000000 ) )
})();</script></body>
</html>
;(function(){
function concatReorderedArray(arr, arr2){
var start = new Date().getTime() ;
if( typeof arr === 'undefined' || arr.length < 1 ) {
console.warn('First array is empty or doesn\'t not exist.')
return false ;
}
if( typeof arr2 === 'undefined' || arr2.length < 1 ) {
console.warn('Second array is empty or doesn\'t not exist.')
return false ;
}
Array.prototype.append = function( array ) {
for( var i = 0, len = array.length; i < len; i++) {
if(typeof array[i] !== 'undefined'){
this.push(array[i]) ;
}
}
}
arr.append(arr2) ;
arr = arr.sort( function( item, item2 ) {
if (item < item2) {
return -1;
}
if (item > item2) {
return 1;
}
return 0;
} ) ;
var end = new Date().getTime() ;
var time = end - start;
console.log(arr);
console.log( 'Array size: ' + arr.length) ;
console.log( 'Execution time: ' + time + 'ms', start, end );
}
function shuffle ( len, range ) {
var arr = [];
for( var i = 0; i < len; i++ ) {
arr.push( Math.floor( ( Math.random() * range ) ) ) ;
}
return arr;
}
concatReorderedArray( shuffle( 50000, 50000000 ), shuffle( 899966, 280000000 ) )
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment