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
6 changes: 6 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ <h2>Dimensions and shapes</h2>
<input type="button" class="btn btn-data" value="size" onclick="dimensionShape(this.value);" />
</p>

<hr />
<h2>Indexing and slicing of matrices</h2>

<p>
<input type="button" class="btn btn-primary" value="access" onclick="accessMatrix();" />
</p>
</div>
</td>
<td id="textbox">
Expand Down
13 changes: 13 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,16 @@ const memorySize = () => {
document.editor.textbox.value+="\nprint('%d bytes' % (" + variable.value + ".size * " + variable.value + ".itemsize))";
}
}

// Indexing and slicing of matrices
const accessMatrix = () => {
if (variable.value === "") {
return alert("Please enter a variable name in the 'variable' field.");
} else if (Math.abs(Number(variable.value)) >= 0) {
return alert("Please do not enter a number in the 'variable' field.");
} else if (indexMatrix.value == "") {
return alert("Please enter a number in the 'index' field.")
} else {
document.editor.textbox.value+= "\n" + variable.value + "[" + indexMatrix.value + "]";
}
}