function squareDigits(num){
return Number(('' + num).split('').map(function (val) { return val * val;}).join(''));
}
function squareDigits(num){
return +num.toString().split('').map(i => i*i).join('');
}
// "ATTGC" --> "TAACG"
// "GTAT" --> "CATA"
let dna='ATTGC'
let p={'A':'T','T':'A','C':'G','G':'C'}
function aa(){
let a=dna.split('').map(function(v){return p[v]}).join('')
return a
}
// logs(10, 2, 3), 0.7781512503836435);
//logs(5, 2, 3), 1.1132827525593785);
function logs(x,a,b){
let m=(Math.log(a*b)/Math.log(x))
return m
}
// (1, 0) --> 1 (1 + 0 = 1)
// (1, 2) --> 3 (1 + 2 = 3)
// (0, 1) --> 1 (0 + 1 = 1)
// (1, 1) --> 1 (1 since both are same)
// (-1, 0) --> -1 (-1 + 0 = -1)
// (-1, 2) --> 2 (-1 + 0 + 1 + 2 = 2)
const GetSum = (a, b) => {
let min = Math.min(a, b),
max = Math.max(a, b);
let v=(max - min + 1) * (min + max) / 2;
return a;
}
// 1
// 3 5
//7 9 11
function rowSumOddNumbers(n) {
let v=Math.pow(n, 3)
return v;
}
//In a small town the population is p0 = 1000 at the beginning of a year. The population regularly increases by 2 percent per year and moreover 50 new inhabitants per year come to live in the town. How many years does the town need to see its population greater than or equal to p = 1200 inhabitants?
// At the end of the first year there will be:
// 1000 + 1000 * 0.02 + 50 => 1070 inhabitants
// At the end of the 2nd year there will be:
// 1070 + 1070 * 0.02 + 50 => 1141 inhabitants (** number of inhabitants is an integer **)
// At the end of the 3rd year there will be:
// 1141 + 1141 * 0.02 + 50 => 1213
// It will need 3 entire years.
function nbYear(p0, percent, aug, p) {
for (var years = 0; p0 < p; years++) {
p0 = Math.floor(p0 + p0 * percent / 100 + aug);
}
return years
}
// 把奇数按升序排序,同时把偶数留在原来的位置。
// [7, 1] => [1, 7]
// [5, 8, 6, 3, 4] => [3, 8, 6, 5, 4]
// [9, 8, 7, 6, 5, 4, 3, 2, 1, 0] => [1, 8, 3, 6, 5, 4, 7, 2, 9, 0]
let arr=[2,7,1,43,355,5,46,32,3,88]
function printerError(s) {
// 建立数组存奇数和index
let oddArr=[]
let oddIndex=[]
// 获得奇数数组
for(let i=0;i<s.length;i++){
if(s[i]%2!==0){
oddArr.push(s[i]);
oddIndex.push(i)
}
}
// 奇数排序
oddArr.sort((a,b)=>{return a-b})
// 替换
for(let j=0;j<oddArr.length;j++){
arr[oddIndex[j]]=oddArr[j]
}
}
// 编写一个函数,接受一个整数作为输入,并返回该整数的二进制表示形式中等于1的位数。你可以保证输入是非负的。
// 示例:1234的二进制表示是10011010010,所以在这种情况下,函数应该返回5
function printerError(n) {
let p =n.toString(2).split('0').join('').length;
return p
}