24 Game LeetCode solution in JavaScript
1/**2* @param {number[]} cards3* @return {boolean}4148757-1 8-46*/7var judgePoint24 = function (cards) {8let minV = 0.00000001;9let numL = [];10cards.forEach((card) => numL.push(card));11function judge(nums) {12if (nums.length === 1) return Math.abs(nums[0] - 24) <= minV;13else {14for (let i = 0; i < nums.length; i++) {15for (let j = 0; j < i; j++) {16let a = nums[i],17b = nums[j];18let val = [a + b, a - b, b - a, a * b, a / b, b / a];19let copy = [...nums];20copy.splice(i, 1);21copy.splice(j, 1);22for (let v of val) {23copy.push(v);24if (judge(copy)) {25return true;26}27copy.pop();28}29}30}31return false;32}33}34return judge(numL);35};