Pinned Loading
-
In an array of ints, return the inde...
In an array of ints, return the index such that the sum of the elements to the right of that index equals the sum of the elements to the left of that index 1function peak(arr) {
2let leftsum = 0;
3let rightsum = 0;
4mid = Math.floor(arr.length / 2)
5const hash = {}
-
A function that accepts a 2D array r...
A function that accepts a 2D array representing a Sudoku board, and returns true if it is a valid solution, or false otherwise. The cells of the sudoku board may also contain 0's, which will represent empty cells. Boards containing one or more zeroes are considered to be invalid solutions. 1function validSolution(board) {
2let valid = true;
3const testvaliditiy = (arr) => {
4let set = new Set(arr);
5if (arr.includes(0) || [...set].length !== 9) {
-
Priority Queue implementation in Jav...
Priority Queue implementation in Javascript 1/**
2* A priority queue stores a list of items but each can have a numeric priority value.
3* Items with a higher priority are dequeued before items with a lower priority.
4* Implemented as a hash of arrays where the hash keys are priority values.
5*/
-
Using async/await in javascript, tra...
Using async/await in javascript, transforming promise to chain to async/await 1function callApi(url){
2return new Promise((resolve,reject) => {
3console.log(`calling API: ${url}`)
4if(url==='twitter'|| url=='facebook'){
5resolve(`connected to ${url}`)
Something went wrong, please refresh the page to try again.
If the problem persists, check the GitHub status page or contact support.
If the problem persists, check the GitHub status page or contact support.