Вы находитесь на странице: 1из 2

Please find below the solution for the second question :

==============================================

function LookAndSay(start, n) {
if (n === 0) {
return start;
}

var txtop = "";


var prev = "";
var count = 0;

var strstart = start + "";


var len = strstart.length;
for (var i=0; i<len; i++) {
var curr = strstart.charAt(i);

if (prev === curr) {


count++;
} else {
if (prev !== "") {
txtop = txtop + count + prev;
}

prev = curr;
count = 1;
}
}

txtop = txtop + count + prev;

var newno = parseInt(txtop);


console.log(newno);
return LookAndSay(newno, n-1);
}

var tt = LookAndSay(1,5);
console.log("tt = " + tt);

Solution to the 3rd question :


===============================

function ConverttoBase7(start) {
var base7 = ['0', 'a', 't', 'l', 's', 's', 'n'];

var strrev = "";


while (start > 0) {
var rem = start % 7;
start = Math.floor(start / 7);
strrev += base7[rem] + "";
}

var strop = "";


var len=strrev.length
for (var i=len-1; i>=0; i--) {
strop += strrev.charAt(i);
}
return strop;
}

var tt = ConverttoBase7(63);
console.log("tt output = " + tt);

=================================

Вам также может понравиться