Loading...
More JavaScript Posts
questions = Array.from(document.querySelectorAll(".multiple-choice-question"));async function hackRadio(question){if(question.querySelector(".question-chevron").getAttribute("aria-label") == "Question completed") return;let answerChoices = question.querySelectorAll(".zb-radio-button");async function guess(answerChoice){answerChoice.querySelector("label").click();}let pause = 0;for(let answerChoice of answerChoices){setTimeout(()=>{guess(answerChoice)},pause); //No need to check given that it will record the correct answer anyways.pause += 1000;}}for(let question of questions){hackRadio(question);}questions = Array.from(document.querySelectorAll(".short-answer-question"));async function hackShortAnswer(question){if(question.querySelector(".question-chevron").getAttribute("aria-label") == "Question completed") return;question.querySelector("textarea").value = question.querySelector(".forfeit-answer").textContent;//question.querySelector(".check-button").click(); They are smart bastards}for(let question of questions){const showAnswerButton = question.querySelector(".show-answer-button");showAnswerButton.click();showAnswerButton.click();hackShortAnswer(question);}
class DoublyLinkedList {constructor() {this.nodes = [];}get size() {return this.nodes.length;}get head() {return this.size ? this.nodes[0] : null;}get tail() {return this.size ? this.nodes[this.size - 1] : null;}insertAt(index, value) {const previousNode = this.nodes[index - 1] || null;const nextNode = this.nodes[index] || null;const node = { value, next: nextNode, previous: previousNode };if (previousNode) previousNode.next = node;if (nextNode) nextNode.previous = node;this.nodes.splice(index, 0, node);}insertFirst(value) {this.insertAt(0, value);}insertLast(value) {this.insertAt(this.size, value);}getAt(index) {return this.nodes[index];}removeAt(index) {const previousNode = this.nodes[index - 1] || null;const nextNode = this.nodes[index + 1] || null;if (previousNode) previousNode.next = nextNode;if (nextNode) nextNode.previous = previousNode;return this.nodes.splice(index, 1);}clear() {this.nodes = [];}reverse() {this.nodes = this.nodes.reduce((acc, { value }) => {const nextNode = acc[0] || null;const node = { value, next: nextNode, previous: null };if (nextNode) nextNode.previous = node;return [node, ...acc];}, []);}*[Symbol.iterator]() {yield* this.nodes;}}const list = new DoublyLinkedList();list.insertFirst(1);list.insertFirst(2);list.insertFirst(3);list.insertLast(4);list.insertAt(3, 5);list.size; // 5list.head.value; // 3list.head.next.value; // 2list.tail.value; // 4list.tail.previous.value; // 5[...list.map(e => e.value)]; // [3, 2, 1, 5, 4]list.removeAt(1); // 2list.getAt(1).value; // 1list.head.next.value; // 1[...list.map(e => e.value)]; // [3, 1, 5, 4]list.reverse();[...list.map(e => e.value)]; // [4, 5, 1, 3]list.clear();list.size; // 0
var invertTree = function(root) {const reverseNode = node => {if (node == null) {return null}reverseNode(node.left);reverseNode(node.right);let holdLeft = node.left;node.left = node.right;node.right = holdLeft;return node;}return reverseNode(root);};
function sortNumbers(arr) {return arr.slice().sort((a, b) => a - b);}const unsortedArray = [4, 1, 9, 6, 3, 5];const sortedArray = sortNumbers(unsortedArray);console.log("Unsorted Numbers:", unsortedArray);console.log("\n");console.log("Sorted Numbers:", sortedArray);
//use this with canvas file finderfunction NewTab(testing) {window.open(testing, "_blank");}for(test in results) {var testing = 'https://unt.instructure.com/files/' + test + '/download';NewTab(testing);}
const compactObject = val => {const data = Array.isArray(val) ? val.filter(Boolean) : val;return Object.keys(data).reduce((acc, key) => {const value = data[key];if (Boolean(value))acc[key] = typeof value === 'object' ? compactObject(value) : value;return acc;},Array.isArray(val) ? [] : {});};const obj = {a: null,b: false,c: true,d: 0,e: 1,f: '',g: 'a',h: [null, false, '', true, 1, 'a'],i: { j: 0, k: false, l: 'a' }};compactObject(obj);// { c: true, e: 1, g: 'a', h: [ true, 1, 'a' ], i: { l: 'a' } }