Skip to content

Commit

Permalink
✏️ style: Partial linting.
Browse files Browse the repository at this point in the history
  • Loading branch information
make-github-pseudonymous-again committed Mar 17, 2021
1 parent b9dcef8 commit fc815aa
Show file tree
Hide file tree
Showing 12 changed files with 680 additions and 811 deletions.
40 changes: 18 additions & 22 deletions doc/scripts/header.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,30 @@
var domReady = function(callback) {
var state = document.readyState ;
if ( state === 'interactive' || state === 'complete' ) {
callback() ;
}
else {
const domReady = function (callback) {
const state = document.readyState;
if (state === 'interactive' || state === 'complete') {
callback();
} else {
document.addEventListener('DOMContentLoaded', callback);
}
} ;

};

domReady(function(){

var projectname = document.createElement('a');
domReady(() => {
const projectname = document.createElement('a');
projectname.classList.add('project-name');
projectname.text = 'aureooms/js-collections-deque';
projectname.href = './index.html' ;
projectname.href = './index.html';

var header = document.getElementsByTagName('header')[0] ;
header.insertBefore(projectname,header.firstChild);
const header = document.querySelectorAll('header')[0];
header.insertBefore(projectname, header.firstChild);

var testlink = document.querySelector('header > a[data-ice="testLink"]') ;
testlink.href = 'https://coveralls.io/github/aureooms/js-collections-deque' ;
testlink.target = '_BLANK' ;
const testlink = document.querySelector('header > a[data-ice="testLink"]');
testlink.href = 'https://coveralls.io/github/aureooms/js-collections-deque';
testlink.target = '_BLANK';

var searchBox = document.querySelector('.search-box');
var input = document.querySelector('.search-input');
const searchBox = document.querySelector('.search-box');
const input = document.querySelector('.search-input');

// active search box when focus on searchBox.
input.addEventListener('focus', function(){
// Active search box when focus on searchBox.
input.addEventListener('focus', () => {
searchBox.classList.add('active');
});

});
36 changes: 21 additions & 15 deletions src/_deque.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
import { TypeError , ValueError } from '@aureooms/js-error' ;
import {TypeError, ValueError} from '@aureooms/js-error';

export default function _deque ( UnboundedDeque , BoundedDeque , SingleElementDeque , EmptyDeque ) {
export default function _deque(UnboundedDeque, BoundedDeque, SingleElementDeque, EmptyDeque) {
const deque = function (iterable = null, maxlen = null) {
if (maxlen === null) {
return new UnboundedDeque(iterable);
}

const deque = function ( iterable = null , maxlen = null ) {
if (!Number.isInteger(maxlen)) {
throw new TypeError(maxlen);
}

if ( maxlen === null ) return new UnboundedDeque( iterable ) ;
if (maxlen === 0) {
return new EmptyDeque(iterable);
}

if ( !Number.isInteger( maxlen ) ) throw new TypeError( maxlen ) ;
if (maxlen === 1) {
return new SingleElementDeque(iterable);
}

if ( maxlen === 0 ) return new EmptyDeque( iterable ) ;
if (maxlen > 0) {
return new BoundedDeque(iterable, maxlen);
}

if ( maxlen === 1 ) return new SingleElementDeque( iterable ) ;

if ( maxlen > 0 ) return new BoundedDeque( iterable , maxlen ) ;

throw new ValueError( maxlen ) ;

} ;

return deque ;
throw new ValueError(maxlen);
};

return deque;
}
18 changes: 8 additions & 10 deletions src/deque.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import {
Deque ,
ArbitrarySizeDeque ,
UnboundedDeque ,
BoundedDeque ,
SingleElementDeque ,
EmptyDeque ,
} from './implementation' ;
UnboundedDeque,
BoundedDeque,
SingleElementDeque,
EmptyDeque
} from './implementation/index.js';

import _deque from './_deque' ;
import _deque from './_deque.js';

const deque = _deque( UnboundedDeque , BoundedDeque , SingleElementDeque , EmptyDeque ) ;
const deque = _deque(UnboundedDeque, BoundedDeque, SingleElementDeque, EmptyDeque);

export default deque ;
export default deque;
54 changes: 27 additions & 27 deletions src/implementation/ArbitrarySizeDeque.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
import Deque from './Deque' ;
import Deque from './Deque.js';

export default function ArbitrarySizeDeque ( ) { }
export default function ArbitrarySizeDeque() {}

ArbitrarySizeDeque.prototype = new Deque( ) ;
ArbitrarySizeDeque.prototype = new Deque();

ArbitrarySizeDeque.prototype.values = function* ( ) {
ArbitrarySizeDeque.prototype.values = function * () {
let i = this.center;
const _m = (i + this.length);
const m = Math.min(this.capacity(), _m);

let i = this.center ;
const _m = ( i + this.length ) ;
const m = Math.min( this.capacity( ) , _m ) ;
for (; i < m; ++i) {
yield this.container[i];
}

for ( ; i < m ; ++i ) yield this.container[i] ;
const n = _m % this.capacity();

const n = _m % this.capacity( ) ;
if (n < _m) {
for (i = 0; i < n; ++i) {
yield this.container[i];
}
}
};

if ( n < _m ) for ( i = 0 ; i < n ; ++i ) yield this.container[i] ;
ArbitrarySizeDeque.prototype.pop = function () {
const [container, index] = this._where(this.length - 1);

} ;
return this._popindex(container, index);
};

ArbitrarySizeDeque.prototype.pop = function ( ) {
ArbitrarySizeDeque.prototype.popleft = function () {
const [container, index] = this._where(0);

const [ container , index ] = this._where( this.length - 1 ) ;
++this.center;
this.center %= this.capacity();

return this._popindex( container , index ) ;

} ;

ArbitrarySizeDeque.prototype.popleft = function ( ) {

const [ container , index ] = this._where( 0 ) ;

++this.center ;
this.center %= this.capacity( ) ;

return this._popindex( container , index ) ;

} ;
return this._popindex(container, index);
};
143 changes: 60 additions & 83 deletions src/implementation/BoundedDeque.js
Original file line number Diff line number Diff line change
@@ -1,109 +1,86 @@
import ArbitrarySizeDeque from './ArbitrarySizeDeque' ;
import ArbitrarySizeDeque from './ArbitrarySizeDeque.js';

export default function BoundedDeque ( iterable , maxlen ) {
export default function BoundedDeque(iterable, maxlen) {
this.maxlen = maxlen;

this.maxlen = maxlen ;
// eslint-disable-next-line unicorn/no-new-array
this.container = new Array(maxlen);

this.container = new Array( maxlen ) ;

this.center = 0 ;

this.length = 0 ;

if ( iterable !== null ) this.extend( iterable ) ;
this.center = 0;

this.length = 0;

if (iterable !== null) {
this.extend(iterable);
}
}

BoundedDeque.prototype = new ArbitrarySizeDeque( ) ;

BoundedDeque.prototype.len = function ( ) {

return this.length ;

} ;

BoundedDeque.prototype.capacity = function ( ) {

return this.maxlen ;

} ;

BoundedDeque.prototype.append = function ( x ) {


if ( this.length === this.maxlen ) {

this.container[this.center] = x ;
++this.center ;
this.center %= this.maxlen ;

BoundedDeque.prototype = new ArbitrarySizeDeque();

BoundedDeque.prototype.len = function () {
return this.length;
};

BoundedDeque.prototype.capacity = function () {
return this.maxlen;
};

BoundedDeque.prototype.append = function (x) {
if (this.length === this.maxlen) {
this.container[this.center] = x;
++this.center;
this.center %= this.maxlen;
} else {
const i = (this.center + this.length) % this.maxlen;
this.container[i] = x;
++this.length;
}

else {
return this;
};

const i = ( this.center + this.length ) % this.maxlen ;
this.container[i] = x ;
++this.length ;
BoundedDeque.prototype.appendleft = function (x) {
--this.center;
this.center += this.maxlen;
this.center %= this.maxlen;
this.container[this.center] = x;

if (this.length < this.maxlen) {
++this.length;
}

return this ;

} ;
return this;
};

BoundedDeque.prototype.appendleft = function ( x ) {
BoundedDeque.prototype.clear = function () {
this.center = 0;

--this.center ;
this.center += this.maxlen ;
this.center %= this.maxlen ;
this.container[this.center] = x ;
this.length = 0;

if ( this.length < this.maxlen ) ++this.length ;
// eslint-disable-next-line unicorn/no-new-array
this.container = new Array(this.maxlen);

return this ;
return this;
};

} ;
BoundedDeque.prototype.copy = function () {
return new BoundedDeque(this, this.maxlen);
};

BoundedDeque.prototype.clear = function ( ) {
BoundedDeque.prototype._where = function (i) {
this._checkbounds(i);

this.center = 0 ;
return [this.container, (this.center + i) % this.maxlen];
};

this.length = 0 ;

this.container = new Array( this.maxlen ) ;

return this ;

} ;

BoundedDeque.prototype.copy = function ( ) {

return new BoundedDeque( this , this.maxlen ) ;

} ;



BoundedDeque.prototype._where = function ( i ) {

this._checkbounds( i ) ;

return [ this.container , ( this.center + i ) % this.maxlen ] ;

} ;


BoundedDeque.prototype._popindex = function ( container , index ) {

const value = container[index] ;
BoundedDeque.prototype._popindex = function (container, index) {
const value = container[index];

// GC
// TODO use null instead of 0 for non-Number deques
container[index] = 0 ;

--this.length ;
container[index] = 0;

return value ;
--this.length;

} ;
return value;
};
Loading

0 comments on commit fc815aa

Please sign in to comment.