Reddit stuff
How do I make an reddit stuff?
What is a reddit stuff? How do you make a reddit stuff? This script and codes were developed by Steven on 31 July 2022, Sunday.
Reddit stuff - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Reddit stuff</title>
</head>
<body> <script src="js/index.js"></script>
</body>
</html>
Reddit stuff - Script Codes JS Codes
// I am stumped at the moment. Essentially I am trying to create a function where it takes a number as a reference and an array, and find a combination (the reference number and two from the array) that equals to zero WITHOUT having any duplicates combination in subArray.
function helper(number, arr){ console.log("Input Array - ", arr) let answer = []; let subArray = [] for(let i = 0; i < arr.length; i++) { for(let y = i + 1; y < arr.length; y++) { subArray.push([arr[i], arr[y]]) //<-- avoid duplicates here } } console.log("Initial Combos -", subArray); subArray = subArray.sort((x, y) => { // Sort properly if (x[0] === y[0]) { return x[1] - y[1]; // Sort by second item } return x[0] - y[0]; // Sort by first (just to make sure) }); // Loop runs backwards to avoid nasty splicing side effects. for (let i = subArray.length -2; i > 0; i--) { // Remove duplicates. if (subArray[i][0] === subArray[i+1][0] && subArray[i][1] === subArray[i+1][1]) { subArray.splice(i, 1); } } console.log("Unique Combos -", subArray); subArray.forEach( combo => { combo.push(number); if (combo.reduce( (accum, value) => accum += value ,0) === 0) { answer.push(combo); } }); return answer;
}
console.clear();
console.log("Result - ", helper(-1, [-1,-1,0,1,2]))
// [ [-1, 0, 1 ], [-1, -1, 2] ]
// We can assume that the array is sorted from the start
// I tried testing using Array.includes but it seems that it doesn't work well with having subArrays.
Developer | Steven |
Username | volv |
Uploaded | July 31, 2022 |
Rating | 3 |
Size | 2,031 Kb |
Views | 38,456 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Tic Tac Toe | 4,862 Kb |
Closure Examples | 2,792 Kb |
A Pen by Steven | 2,755 Kb |
Recursive Tree | 3,381 Kb |
Heavy Snake | 6,358 Kb |
Squares Within Range | 2,853 Kb |
Midas Gift Rolls - Updating | 2,897 Kb |
Beer Event - Remaining Rewards | 2,537 Kb |
Recursive Multiplication | 2,119 Kb |
Nested Loops | 2,231 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
About Mazano | Kiti | 2,585 Kb |
Flexbox Test | Icutpeople | 2,486 Kb |
Loading animation | Codeams | 2,408 Kb |
Ripples in water | Nobitagit | 2,704 Kb |
APortfolio | Skybutterfly | 5,174 Kb |
Factorial | KeithleySLHS | 1,158 Kb |
RRC wrapSwitch | Pshrmn | 2,922 Kb |
HTM5 picture dropzone | Jaysalvat | 2,576 Kb |
Sencha Touch 2.3.1 Basic Grid Example | Trozdol | 2,770 Kb |
3D Text in Sass | Bookcasey | 2,766 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!