JavaScript Persistence bugger codewars kata

  • Thread starter Thread starter shivajikobardan
  • Start date Start date
AI Thread Summary
The discussion revolves around a coding challenge from Codewars that involves creating a function to determine how many times the digits of a number must be multiplied together until a single-digit result is achieved. The initial code provided incorrectly returns the final product instead of the count of multiplications required. The user identifies the issue and acknowledges the need to modify the function to correctly track and return the number of iterations needed to reach a single digit. The conversation highlights the importance of understanding the problem requirements and ensuring the function's output aligns with those expectations.
shivajikobardan
Messages
637
Reaction score
54
TL;DR Summary
kata not solved.
I'm solving this kata:
https://www.codewars.com/kata/55bf01e5a717a0d57e0000ec/train/javascript

JavaScript:
function persistence(n) {
  var str = n.toString();
  let finalproduct;

  if (str.length == 1) {
    return 0;
  }

  do {
    finalproduct = sop(str);
    str = finalproduct;
    str = str.toString();
  } while (str.length > 1);

  return finalproduct;
}

function sop(str1) {
  let product = 1;
  for (let i = 0; i < str1.length; i++) {
    product = product * Number(str1[i]);
  }

  return product;
}

persistence(4);
Here's my code but it is not passing few tests. Why's that?
ZNoy6yAJnRrC-jvZ4e9U4DT0bd3iT0uHwgrKdOc6iR-O-umVmA.png
 
Last edited by a moderator:
Technology news on Phys.org
Your function doesn't return what the problem asks for: the number of times you must multiply the digits in num until you reach a single digit.
 
DrClaude said:
Your function doesn't return what the problem asks for: the number of times you must multiply the digits in num until you reach a single digit.
thanks fixed it.
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...

Similar threads

Replies
7
Views
1K
Replies
1
Views
1K
Replies
2
Views
2K
Replies
11
Views
4K
Replies
12
Views
2K
Replies
1
Views
2K
Back
Top