/** * @param {any[]} arr */ functionshuffle(array) { // modify the arr inline to change the order randomly for (let i = array.length - 1; i > 0; i--) { let j = Math.floor(Math.random() * (i + 1)); [array[i], array[j]] = [array[j], array[i]]; } }
/** * @param {string[][]} message * @return {string} */ functiondecode(message) { // your code here let result = ""; let cols = message[0]?.length; let direction = 1, i = 0, j = 0; while(cols > j) { result += message[i][j]; if(!message[i+direction]) { direction *= -1; } i += direction; j++; } return result; }
/** * @param {TypIsBad} isBad */ functionfirstBadVersion(isBad) { // firstBadVersion receive a check function isBad // and should return a closure which accepts a version number(integer) return(version) => { // write your code to return the first bad version // if none found, return -1 let start = 0; let end = version; while(start <= end) { let mid = Math.floor((start+end)/2); if(isBad(mid)) { end = mid - 1; } else { start = mid + 1; } } return start <= version ? start : -1; } }
/* you can use this Class which is bundled together with your code
class Stack { push(element) { // add element to stack } peek() { // get the top element } pop() { // remove the top element} size() { // count of element } } */
/* Array is disabled in your code */
// you need to complete the following Class classQueue { constructor() { this.stack = newStack(); }
enqueue(element) { // add new element to the rare this.stack.push(element); } peek() { // get the head element let rStack = this._reverse(this.stack); let result = rStack.peek(); this.stack = this._reverse(rStack); return result; } size() { // return count of element returnthis.stack.size(); } dequeue() { // remove the head element let rStack = this._reverse(this.stack); let result = rStack.pop(); this.stack = this._reverse(rStack); return result; }
/** * @param {HTMLElement} el - element to be wrapped */ function$(el) { // your code here return { css(prop, value) { el.style[prop] = value; returnthis; } } }