Recursive Multiplication

Developer
Size
2,119 Kb
Views
58,696

How do I make an recursive multiplication?

Challenged to do multiplication without using *. What is a recursive multiplication? How do you make a recursive multiplication? This script and codes were developed by Steven on 24 September 2022, Saturday.

Recursive Multiplication Previews

Recursive Multiplication - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Recursive Multiplication</title>
</head>
<body> <script src="js/index.js"></script>
</body>
</html>

Recursive Multiplication - Script Codes JS Codes

"use strict";
// Or some recursion perhaps
// Less lazy, handled signs. Feels like I'm missing a trick though.
function mult(x, y) { var resultSign = x < 0 ? // x less than zero y > 0 ? -1 : 1 : // x greater than zero y < 0 ? -1 : 1; x = volvAbs(x); y = volvAbs(y); function doMult(x, y) { if (y === 0) return 0; // End recursion return x + doMult(x, y - 1); } return resultSign === 1 ? doMult(x, y) : -doMult(x, y);
}
function volvAbs(x) { // Stupid negatives return x < 0 ? -x : x;
}
console.clear();
console.log(mult(6, 7)); // 42
console.log(mult(-6, 7)); //-42
console.log(mult(6, -7)); //-42
console.log(mult(-6, -7)); // 42
Recursive Multiplication - Script Codes
Recursive Multiplication - Script Codes
Home Page Home
Developer Steven
Username volv
Uploaded September 24, 2022
Rating 3
Size 2,119 Kb
Views 58,696
Do you need developer help for Recursive Multiplication?

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 SEO 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!