This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "math/rand" | |
| ) | |
| func main() { | |
| symbols := []string{"🍒", "🍋", "🔔", "💎", "7️⃣", "🍀", "🎉", "🙁", "🎲"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| ) | |
| type Node { | |
| value string | |
| next *Node | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class TreeNode { | |
| constructor(data) { | |
| this.str = "\n" | |
| this.value = data | |
| this.left = null | |
| this.right = null | |
| } | |
| length(root) { | |
| if(!root) return 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const arr = [5, 4, 1, 2, 8, 10] | |
| arr.forEach(num => { | |
| setTimeout(() => console.log(item), num * 0.5) | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class BinaryMath { | |
| static sum(a, b) { | |
| let carry = (a & b) | |
| carry = carry << 1 | |
| return carry === 0 | |
| ? b | |
| : this.sum(carry, b) | |
| } | |
| static sub(a, b) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function filterAnd(array, values) { | |
| return array.filter(item => | |
| Object.keys(values).every(key => item[key] === values[key]) | |
| ) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function weirdRecusriveSum(nums, length, result = 0, index = 0, memo = {}){ | |
| if(length === 0) return result | |
| if(result in memo) return memo[result] | |
| result += nums[index] | |
| length-- | |
| index++ | |
| memo[result] = weirdRecusriveSum(nums, length, result, index, memo) | |
| return memo[result] | |
| } | |
| const sum = new Array(4500).fill(1).map((t,i)=> t+i) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function spiralize(n) { | |
| return Array(n).fill(Array(n).fill(0)).map((i, row) => i.map((j, col) => { | |
| const north = row < n / 2 && row % 2 === 0 && col >= row - 1 && col <= n - row - 1 | |
| const east = (n-col) % 2 === 1 && row <= col && row > n - col - 1 | |
| const south = (n-row) % 2 === 1 && col < row && col > n - row - 1 | |
| const west = col % 2 === 0 && row < n - col && row > col + 1 | |
| const result = north || east || south || west | |
| return Number(result) | |
| })) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function isFreeSpace(maze, x, y) { | |
| return ( | |
| y >= 0 && | |
| y < maze.length && | |
| x >= 0 && | |
| x < maze[0].length && | |
| maze[y][x] === 0 | |
| ) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function drawLine(start, end) { | |
| const points = [] | |
| if(start.x === end.x && start.y === end.y) { | |
| return [start] | |
| } | |
| const dx = Math.abs(end.x - start.x) | |
| const dy = Math.abs(end.y - start.y) | |
| const distance = Math.max(dx, dy) |
NewerOlder