Here is the [Kata] for reference (https://www.codewars.com/kata/564057bc348c7200bd0000ff/train/javascript)
I have no Idea why it wont accept my function. its saying

This is my code, it works elsewhere
function thirt(n)
{
var array = n.split('')
console.log(array)
var arrayReverse=array.reverse()
console.log(arrayReverse)
var arrayTimes = []
var arrayremainders = [1, 10, 9, 12, 3, 4]
for(x=0;x<n.length;x++)
{
var sequence
if(x%6===0)
{
sequence = 0
}
else
{
sequence = x%6
}
console.log(arrayReverse[x]+' X '+arrayremainders
[sequence])
console.log('arrayReverse'+' X '+'arrayremainders')
arrayTimes.push(arrayReverse[x]*arrayremainders[sequence])
}
console.log(arrayTimes)
function addsum (total,num)
{
return total+num
}
var answer = arrayTimes.reduce(addsum,0)
console.log(answer)
return answer
}
At some point, your function is receiving a value that is not a string.
Ok I need a way of repeatedly calling this function until n (>=0) “x is greater than or = 0” I think thats what it wants
so I have the way to do it once
function thirt(n)
{
var static = n
var arrayremainders = [1, 10, 9, 12, 3, 4]
function arrayTimes(array)
{
var array = n.split('')
console.log(array)
var arrayReverse=array.reverse()
console.log(arrayReverse)
var arrayTimes = []
for(x=0;x<n.length;x++)
{
var sequence
if(x%6===0)
{
sequence = 0
}
else
{
sequence = x%6
}
console.log(arrayReverse[x]+' X '+arrayremainders
[sequence])
console.log('arrayReverse'+' X '+'arrayremainders')
arrayTimes.push(arrayReverse[x]*arrayremainders[sequence])
}
console.log(arrayTimes)
function addsum (total,num)
{
return total+num
}
static = arrayTimes.reduce(addsum,0)
console.log(static)
}
arrayTimes(n)
}
thirt("1234567")
Ok this is pissing me off but I am pretty sure this works
for all of their basic tests except for 987654321 which should be 303 not 30 I think
Test.it("Basic tests",function() {
Test.assertEquals(thirt(8529), 79)
Test.assertEquals(thirt(85299258), 31)
Test.assertEquals(thirt(5634), 57)
Test.assertEquals(thirt(1111111111), 71)
Test.assertEquals(thirt(987654321), 30)
})})
Im still getting that n.split error which I dont understand, it works on the compiler im using
function thirt(n)
{
var static = String(n)
var arrayremainders = [1, 10, 9, 12, 3, 4]
function arrayTimes(array)
{
var array = n.split('')
console.log(array)
var arrayReverse=array.reverse()
console.log(arrayReverse)
var arrayTimes = []
for(x=0;x<n.length;x++)
{
var sequence
if(x%6===0)
{
sequence = 0
}
else
{
sequence = x%6
}
console.log(arrayReverse[x]+' X '+arrayremainders
[sequence])
console.log('arrayReverse'+' X '+'arrayremainders')
arrayTimes.push(arrayReverse[x]*arrayremainders[sequence])
}
console.log(arrayTimes)
function addsum (total,num)
{
return total+num
}
static = arrayTimes.reduce(addsum,0)
console.log(static)
}
if(arrayTimes(static)===static)
{
return static
}
else
{
arrayTimes(static)
}
}
split()
is a string method. It looks like your thirt
function is expected to take an integer. You cannot split
an integer.
I considered this so I added static = String(n)
shouldnt this ensure that its a string before I tried to split it so there shouldnt be an issue
But you aren’t splitting static
. You’re splitting n
, which is still an integer.
oh balls just noticed im still calling it on the n lol thanks