Minimize .length checks in JavaScript

This doesn't change anything but is just a code style question. I
find it less confusing than a numeric comparison, to be honest.

Change-Id: I6ef220e85e395fe4769103e20402e1e540946778
This commit is contained in:
thiemowmde 2024-11-21 09:50:19 +01:00
parent 4396f4453f
commit f3be60464e
3 changed files with 5 additions and 5 deletions

View file

@ -153,7 +153,7 @@ Object.assign( Api.prototype, {
* @return {jQuery.jqXHR}
*/
fetchUserGenderData: function ( users ) {
if ( users.length === 0 ) {
if ( !users.length ) {
return $.Deferred().resolve();
}
return $.ajax( {

View file

@ -154,7 +154,7 @@ Object.assign( RevisionListView.prototype, {
$neighborRevisionWrapper = $revisionWrapper.next();
}
if ( $neighborRevisionWrapper.length === 0 ) {
if ( !$neighborRevisionWrapper.length ) {
return;
}

View file

@ -726,7 +726,7 @@ Object.assign( SliderView.prototype, {
if ( this.getOlderPointerPos() !== 0 || this.getNewerPointerPos() !== 0 ) {
return;
}
if ( $oldRevElement.length === 0 && $newRevElement.length === 0 ) {
if ( !$oldRevElement.length && !$newRevElement.length ) {
// Note: this is currently caught in init.js
throw new Error( 'RS-revs-not-specified' );
}
@ -966,7 +966,7 @@ Object.assign( SliderView.prototype, {
changeTags: this.slider.getRevisionList().getAvailableTags()
} ).then( ( data ) => {
const revs = data.revisions.slice( 1 );
if ( revs.length === 0 ) {
if ( !revs.length ) {
self.noMoreNewerRevisions = true;
return;
}
@ -1002,7 +1002,7 @@ Object.assign( SliderView.prototype, {
changeTags: this.slider.getRevisionList().getAvailableTags()
} ).then( ( data ) => {
let revs = data.revisions.slice( 1 ).reverse();
if ( revs.length === 0 ) {
if ( !revs.length ) {
self.noMoreOlderRevisions = true;
return;
}