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} * @return {jQuery.jqXHR}
*/ */
fetchUserGenderData: function ( users ) { fetchUserGenderData: function ( users ) {
if ( users.length === 0 ) { if ( !users.length ) {
return $.Deferred().resolve(); return $.Deferred().resolve();
} }
return $.ajax( { return $.ajax( {

View file

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

View file

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