Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,43 @@ <h2>Broadcasting and vectorized operations</h2>
<input class="btn" name="broadcastNumber" id="broadcastNumber" placeholder="value" type="number" />
</p>

<hr />
<h2>Boolean arrays (masks)</h2>

<p>
<input type="button" class="btn btn-primary" value=">" onclick="boolean(this.value)" />
<input type="button" class="btn btn-primary" value=">=" onclick="boolean(this.value)" />
<input type="button" class="btn btn-primary" value="<" onclick="boolean(this.value)" />
<input type="button" class="btn btn-primary" value="<=" onclick="boolean(this.value)" />
<input type="button" class="btn btn-primary" value="==" onclick="boolean(this.value)" />
<input type="button" class="btn btn-primary" value="!=" onclick="boolean(this.value)" />
</p>

<p>
<input type="button" class="btn btn-primary" value="&" onclick="masks(this.value)" />
<input type="button" class="btn btn-primary" value="|" onclick="masks(this.value)" />
</p>

<p>
<input class="btn" name="valueA" id="valueA" placeholder="value A" size="10" type="textfield" />
<input class="btn" name="valueB" id="valueB" placeholder="value B" size="10" type="textfield" />
</p>

<p>
<input type="button" class="btn btn-primary" value="start True" onclick="truthy('True')" />
<input type="button" class="btn btn-primary" value="start False" onclick="truthy('False')" />
</p>

<p>
<input type="button" class="btn btn-primary" value="@ True" onclick="document.editor.textbox.value+=', True'" />
<input type="button" class="btn btn-primary" value="@ False" onclick="document.editor.textbox.value+=', False'" />
</p>

<p>
<input type="button" class="btn btn-primary" value="last True" onclick="document.editor.textbox.value+=', True]\n'" />
<input type="button" class="btn btn-primary" value="last False" onclick="document.editor.textbox.value+=', False]\n'" />
</p>

</div>
</td>
<td id="textbox">
Expand Down
36 changes: 36 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,3 +266,39 @@ const operation = (arg) => {
document.editor.textbox.value+="\n" + variable.value + " " + arg + " " + broadcastNumber.value;
}
}

// Boolean arrays (masks)
let valueA = document.getElementById("valueA");
let valueB = document.getElementById("valueB");

const boolean = (arg) => {
if (variable.value === "") {
return alert("Please enter a variable name in the 'variable' field, in the 'Basic NumPy arrays' section.");
} else if (valueA.value === "") {
return alert("Please enter a value in the 'value A' field, in the 'Boolean arrays (masks)' section.");
} else if (valueB.value === "") {
return alert("Please enter a value in the 'value B' field, in the 'Boolean arrays (masks)' section.");
} else {
document.editor.textbox.value+="\n" + variable.value + "[" + valueA.value + " " + arg + " " + valueB.value + "]";
}
}

const masks = (arg) => {
if (variable.value === "") {
return alert("Please enter a variable name in the 'variable' field, in the 'Basic NumPy arrays' section.");
} else if (valueA.value === '') {
return alert("Please enter a value in the 'value A' field, in the 'Boolean arrays (masks)' section.");
} else if (valueB.value === '') {
return alert("Please enter a value in the 'value B' field, in the 'Boolean arrays (masks)' section.");
} else {
document.editor.textbox.value+="\n" + variable.value + "[(" + valueA.value + ") " + arg + " (" + valueB.value + ")]";
}
}

const truthy = (arg) => {
if (variable.value === "") {
return alert("Please enter a variable name in the 'variable' field, in the 'Basic NumPy arrays' section.");
} else {
document.editor.textbox.value+="\n" + variable.value + "[" + arg;
}
}