Reddit stuff

Developer
Size
2,031 Kb
Views
38,456

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 Previews

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.
Reddit stuff - Script Codes
Reddit stuff - Script Codes
Home Page Home
Developer Steven
Username volv
Uploaded July 31, 2022
Rating 3
Size 2,031 Kb
Views 38,456
Do you need developer help for Reddit stuff?

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!

Steven (volv) Script Codes
Create amazing web content with AI!

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!