Skip to content

Commit

Permalink
refactor: update indexOf () === -1 to ! includes (#4001)
Browse files Browse the repository at this point in the history
* update PitchBlocks.js

* update ProgramBlocks.js

* update VolumeBlocks.js

* update WidgetBlocks.js

* update IntervalsActions.js

* update PitchActions.js

* update RhythmActions.js

* update ToneActions.js

* update VolumeActions.js

* update utils.js

* update arpeggio.js

* update musickeyboards.js

* update phrasemaker.js

* update rhythmruler.js

* update generate.js

* update interface.js

* update mathutils.js

* update synthutils.js

* update help.js

* update helper.js
  • Loading branch information
haroon10725 committed Sep 13, 2024
1 parent f410648 commit 9e62e67
Show file tree
Hide file tree
Showing 20 changed files with 117 additions and 117 deletions.
36 changes: 18 additions & 18 deletions js/blocks/PitchBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,20 +523,20 @@ function setupPitchBlocks(activity) {
// Check to see if the octave was included.
const lastChar = arg1.charAt(arg1.length - 1);
let foundOctave = "";
if ("12345678".indexOf(lastChar) !== -1) {
if ("12345678".includes(lastChar)) {
foundOctave = lastChar;
arg1 = arg1.slice(0, arg1.length - 1);
}
if (SOLFEGENAMES1.indexOf(arg1) !== -1) {
if (SOLFEGENAMES1.includes(arg1)) {
let sol = arg1;
let attr;
if (sol.indexOf(SHARP) != -1) {
if (sol.includes(SHARP)) {
attr = SHARP;
} else if (sol.indexOf(FLAT) != -1) {
} else if (sol.includes(FLAT)) {
attr = FLAT;
} else if (sol.indexOf(DOUBLEFLAT) != -1) {
} else if (sol.includes(DOUBLEFLAT)) {
attr = DOUBLEFLAT;
} else if (sol.indexOf(DOUBLESHARP) != -1) {
} else if (sol.includes(DOUBLESHARP)) {
attr = DOUBLESHARP;
} else {
attr = NATURAL;
Expand All @@ -555,15 +555,15 @@ function setupPitchBlocks(activity) {
} else {
notePlayed += foundOctave;
}
} else if (NOTENAMES1.indexOf(arg1) !== -1) {
} else if (NOTENAMES1.includes(arg1)) {
if (foundOctave.length === 0) {
notePlayed =
arg1 +
(tur.singer.currentOctave ? tur.singer.currentOctave : 4);
} else {
notePlayed = arg1 + foundOctave;
}
} else if (ALLNOTENAMES.indexOf(arg1) !== -1) {
} else if (ALLNOTENAMES.includes(arg1)) {
// Why would the accidental be "b or #"?
if (foundOctave.length === 0) {
notePlayed =
Expand Down Expand Up @@ -1605,7 +1605,7 @@ function setupPitchBlocks(activity) {
logo.stopTurtle = true;
} else if (logo.inMatrix) {
logo.phraseMaker.addRowBlock(blk);
if (logo.pitchBlocks.indexOf(blk) === -1) {
if (!logo.pitchBlocks.includes(blk)) {
logo.pitchBlocks.push(blk);
}

Expand Down Expand Up @@ -1897,13 +1897,13 @@ function setupPitchBlocks(activity) {
let scaledegree = activity.blocks.blockList[c].value;
let attr;

if (scaledegree.indexOf(SHARP) !== -1) {
if (scaledegree.includes(SHARP)) {
attr = SHARP;
} else if (scaledegree.indexOf(FLAT) !== -1) {
} else if (scaledegree.includes(FLAT)) {
attr = FLAT;
} else if (scaledegree.indexOf(DOUBLESHARP) !== -1) {
} else if (scaledegree.includes(DOUBLESHARP)) {
attr = DOUBLESHARP;
} else if (scaledegree.indexOf(DOUBLEFLAT) !== -1) {
} else if (scaledegree.includes(DOUBLEFLAT)) {
attr = DOUBLEFLAT;
} else {
attr = NATURAL;
Expand Down Expand Up @@ -1942,7 +1942,7 @@ function setupPitchBlocks(activity) {
let semitones = ref;

semitones +=
NOTESFLAT.indexOf(note) !== -1
NOTESFLAT.includes(note)
? NOTESFLAT.indexOf(note) - ref
: NOTESSHARP.indexOf(note) - ref;

Expand Down Expand Up @@ -2007,18 +2007,18 @@ function setupPitchBlocks(activity) {

// Check if string ends with accidental
if (
SOLFEGENAMES1.indexOf(arg0.toLowerCase()) !== -1 ||
NOTENAMES1.indexOf(arg0.toUpperCase()) !== -1
SOLFEGENAMES1.includes(arg0.toLowerCase()) ||
NOTENAMES1.includes(arg0.toUpperCase())
) {
// Store accidental
let accSym = arg0.charAt(arg0.length - 1);
if ([SHARP, FLAT, DOUBLESHARP, DOUBLEFLAT].indexOf(accSym) === -1) {
if (![SHARP, FLAT, DOUBLESHARP, DOUBLEFLAT].includes(accSym)) {
accSym = NATURAL;
} else {
arg0 = arg0.substr(0, arg0.length - 1);
}
note =
NOTENAMES.indexOf(arg0.toUpperCase()) !== -1
NOTENAMES.includes(arg0.toUpperCase())
? SOLFEGECONVERSIONTABLE[arg0.toUpperCase()]
: arg0;
note = accSym !== NATURAL ? note + accSym : note; // add accidental
Expand Down
8 changes: 4 additions & 4 deletions js/blocks/ProgramBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -1297,18 +1297,18 @@ function setupProgramBlocks(activity) {
if (i < blockArgs.length) {
if (typeof blockArgs[i] === "number") {
if (
["anyin", "numberin"].indexOf(
!["anyin", "numberin"].includes(
activity.blocks.protoBlockDict[protoblk].dockTypes[i]
) === -1
)
) {
activity.errorMsg(_("Warning: block argument type mismatch"));
}
newBlock.push([i, ["number", { value: blockArgs[i] }], 0, 0, [0]]);
} else if (typeof blockArgs[i] === "string") {
if (
["anyin", "textin"].indexOf(
!["anyin", "textin"].includes(
activity.blocks.protoBlockDict[protoblk].dockTypes[i]
) === -1
)
) {
activity.errorMsg(_("Warning: block argument type mismatch"));
}
Expand Down
2 changes: 1 addition & 1 deletion js/blocks/VolumeBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ function setupVolumeBlocks(activity) {

const tur = activity.turtles.ithTurtle(turtle);

if (tur.singer.instrumentNames.indexOf(synth) === -1) {
if (!tur.singer.instrumentNames.includes(synth)) {
tur.singer.instrumentNames.push(synth);
logo.synth.loadSynth(turtle, synth);

Expand Down
2 changes: 1 addition & 1 deletion js/blocks/WidgetBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ function setupWidgetBlocks(activity) {
}
}

if ([-12, -24, -48, -96].indexOf(args[1]) === -1) {
if (![-12, -24, -48, -96].includes(args[1])) {
//.TRANS: rolloff is the steepness of a change in frequency.
activity.errorMsg(
_("Rolloff value should be either -12, -24, -48, or -96 decibels/octave.")
Expand Down
2 changes: 1 addition & 1 deletion js/js-export/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class JSGenerate {
while (nextBlk !== undefined) {
// ignore vertical spacers and hidden blocks
if (nextBlk.name !== "hidden" && nextBlk.name !== "vspace") {
if (["storein2", "nameddo"].indexOf(nextBlk.name) !== -1) {
if (["storein2", "nameddo"].includes(nextBlk.name)) {
tree.push([nextBlk.name + "_" + nextBlk.privateData]);
} else {
tree.push([nextBlk.name]);
Expand Down
24 changes: 12 additions & 12 deletions js/js-export/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ class JSInterface {
* @returns {Boolean}
*/
static isClampBlock(blockName) {
return JSInterface._clampBlocks.indexOf(blockName) !== -1;
return JSInterface._clampBlocks.includes(blockName);
}

/**
Expand Down Expand Up @@ -288,7 +288,7 @@ class JSInterface {
* @returns {Boolean}
*/
static methodReturns(blockName) {
return JSInterface._returningMethods.indexOf(blockName) !== -1;
return JSInterface._returningMethods.includes(blockName);
}

/**
Expand Down Expand Up @@ -439,10 +439,10 @@ class JSInterface {
const solfeges = ["do", "re", "mi", "fa", "sol", "la", "ti"];
const letters = ["c", "d", "e", "f", "g", "a", "b"];
if (
solfeges.indexOf(strs[0].toLowerCase()) !== -1 ||
letters.indexOf(strs[0].toLowerCase()) !== -1
solfeges.includes(strs[0].toLowerCase()) ||
letters.includes(strs[0].toLowerCase())
) {
if (solfeges.indexOf(strs[0].toLowerCase()) !== -1) {
if (solfeges.includes(strs[0].toLowerCase())) {
arg = strs[0].toLowerCase();
} else {
arg = strs[0].toUpperCase();
Expand All @@ -457,7 +457,7 @@ class JSInterface {
doubleflat: DOUBLEFLAT
};

if (accidentals.indexOf(strs[1]) !== -1) {
if (accidentals.includes(strs[1])) {
arg += strs[1];
} else if (strs[1].toLowerCase() in accidentals2) {
arg += accidentals2[strs[1].toLowerCase()];
Expand All @@ -484,9 +484,9 @@ class JSInterface {
"doubleflat"
];

if (accidentals.indexOf(arg) !== -1) {
if (accidentals.includes(arg)) {
arg = accidentalOuts[accidentals.indexOf(arg)];
} else if (accidentals2.indexOf(arg.toLowerCase()) !== -1) {
} else if (accidentals2.includes(arg.toLowerCase())) {
arg = accidentalOuts[accidentals2.indexOf(arg.toLowerCase())];
}
} else if (props["constraints"]["type"] === "oneof") {
Expand Down Expand Up @@ -546,7 +546,7 @@ class JSInterface {
"triangle",
"vibraphone"
];
if (instruments.indexOf(arg) !== -1) {
if (instruments.includes(arg)) {
arg = arg.toLowerCase();
} else {
JSEditor.logConsole(
Expand Down Expand Up @@ -576,7 +576,7 @@ class JSInterface {
"slap",
"raindrop"
];
if (drums.indexOf(arg) !== -1) {
if (drums.includes(arg)) {
arg = arg.toLowerCase();
} else {
JSEditor.logConsole(
Expand All @@ -600,7 +600,7 @@ class JSInterface {
} else if (props["constraints"]["type"] === "letterkey") {
const strs = arg.split(" ");
const letters = ["c", "d", "e", "f", "g", "a", "b"];
if (letters.indexOf(strs[0].toLowerCase()) !== -1) {
if (letters.includes(strs[0].toLowerCase())) {
arg = strs[0].toUpperCase();

if (strs.length > 1) {
Expand All @@ -612,7 +612,7 @@ class JSInterface {
doubleflat: DOUBLEFLAT
};

if (accidentals.indexOf(strs[1]) !== -1) {
if (accidentals.includes(strs[1])) {
arg += strs[1];
} else if (strs[1].toLowerCase() in accidentals2) {
arg += accidentals2[strs[1].toLowerCase()];
Expand Down
2 changes: 1 addition & 1 deletion js/turtleactions/IntervalsActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ function setupIntervalsActions(activity) {

const __listener = () => {
MUSICALMODES[modeName] = [];
if (tur.singer.defineMode.indexOf(0) === -1) {
if (!tur.singer.defineMode.includes(0)) {
tur.singer.defineMode.push(0);
activity.errorMsg(_("Adding missing pitch number 0."));
}
Expand Down
2 changes: 1 addition & 1 deletion js/turtleactions/PitchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ function setupPitchActions(activity) {
const note = nthDegreeToPitch(tur.singer.keySignature, scaleDegree);
let semitones = ref;
semitones +=
NOTESFLAT.indexOf(note) !== -1
NOTESFLAT.includes(note)
? NOTESFLAT.indexOf(note) - ref
: NOTESSHARP.indexOf(note) - ref;
/** calculates changes in reference octave which occur a semitone before the reference key */
Expand Down
6 changes: 3 additions & 3 deletions js/turtleactions/RhythmActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ function setupRhythmActions(activity) {
*/
const turtleID = tur.id;

if (tur.singer.beatList.indexOf("everybeat") !== -1) {
if (tur.singer.beatList.includes("everybeat")) {
_enqueue();
activity.stage.dispatchEvent("__everybeat_" + turtleID + "__");
}

if (tur.singer.beatList.indexOf(beatValue) !== -1) {
if (tur.singer.beatList.includes(beatValue)) {
_enqueue();
activity.stage.dispatchEvent("__beat_" + beatValue + "_" + turtleID + "__");
} else if (beatValue > 1 && tur.singer.beatList.indexOf("offbeat") !== -1) {
} else if (beatValue > 1 && tur.singer.beatList.includes("offbeat")) {
_enqueue();
activity.stage.dispatchEvent("__offbeat_" + turtleID + "__");
}
Expand Down
2 changes: 1 addition & 1 deletion js/turtleactions/ToneActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function setupToneActions(activity) {
activity.logo.phraseMaker._instrumentName = synth;
}

if (tur.singer.instrumentNames.indexOf(synth) === -1) {
if (!tur.singer.instrumentNames.includes(synth)) {
tur.singer.instrumentNames.push(synth);
activity.logo.synth.loadSynth(turtle, synth);

Expand Down
2 changes: 1 addition & 1 deletion js/turtleactions/VolumeActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ function setupVolumeActions(activity) {

const tur = activity.turtles.ithTurtle(turtle);

if (tur.singer.instrumentNames.indexOf(synth) === -1) {
if (!tur.singer.instrumentNames.includes(synth)) {
tur.singer.instrumentNames.push(synth);
activity.logo.synth.loadSynth(turtle, synth);

Expand Down
4 changes: 2 additions & 2 deletions js/utils/mathutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ class MathUtility {
} else if (
typeof a === "string" &&
typeof b === "string" &&
SOLFEGENAMES.indexOf(a) !== -1 &&
SOLFEGENAMES.indexOf(b) !== -1
SOLFEGENAMES.includes(a) &&
SOLFEGENAMES.includes(b)
) {
return GetRandomSolfege(a, b, c);
} else {
Expand Down
2 changes: 1 addition & 1 deletion js/utils/synthutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1737,7 +1737,7 @@ function Synth() {
future
);
// Effects don't work with sine, sawtooth, et al.
if (["sine", "sawtooth", "triangle", "square"].indexOf(instrumentName) !== -1) {
if (["sine", "sawtooth", "triangle", "square"].includes(instrumentName)) {
paramsEffects = null;
} else if (paramsEffects !== null && paramsEffects !== undefined) {
if (paramsEffects["vibratoIntensity"] !== 0) {
Expand Down
2 changes: 1 addition & 1 deletion js/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ const processPluginData = (activity, pluginData) => {
// eslint-disable-next-line no-console
console.debug("adding palette " + name);
activity.palettes.add(name);
if (MULTIPALETTES[2].indexOf(name) === -1) MULTIPALETTES[2].push(name);
if (!MULTIPALETTES[2].includes(name)) MULTIPALETTES[2].push(name);
newPalette = true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion js/widgets/arpeggio.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ class Arpeggio {
* @returns {boolean} true/false
*/
_inMode(i) {
return this._modeNumbers.indexOf(i.toString()) !== -1;
return this._modeNumbers.includes(i.toString());
}

/**
Expand Down
4 changes: 2 additions & 2 deletions js/widgets/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ class HelpWidget {
_("Guide"),
_("About"),
_("Congratulations.")
].indexOf(HELPCONTENT[page][0]) !== -1
].includes(HELPCONTENT[page][0])
) {
// body = body + '<p>&nbsp;<img src="' + HELPCONTENT[page][2] + '"></p>';
body = `<figure>&nbsp;<img src=" ${HELPCONTENT[page][2]}"></figure>` ;
Expand All @@ -356,7 +356,7 @@ class HelpWidget {
body += `<p><a href="${link}" target="_blank">${HELPCONTENT[page][4]}</a></p>` ;
}

if ([_("Congratulations.")].indexOf(HELPCONTENT[page][0]) !== -1) {
if ([_("Congratulations.")].includes(HELPCONTENT[page][0])) {
const cell = docById("right-arrow");

cell.onclick = () => {
Expand Down
Loading

0 comments on commit 9e62e67

Please sign in to comment.