[7 kyu] Disarium Number (Special Numbers Series #3)
Definition
Disarium number is the number that The sum of its digits powered with their respective positions is equal to the number itself.
Task
Given a number, Find if it is Disarium or not.
Warm-up (Highly recommended)
Playing With Numbers Series
Notes
Number passed is always Positive .
-
Return the result as String
Input >> Output Examples
disariumNumber(89) ==> return "Disarium !!"
Explanation:
- Since , 81 + 92 = 89 , thus output is `"Disarium !!"
翻译:
给定一个数字,确定它是否为Disarium。
解:
function disariumNumber(n){
return
n.toString().split('').map((x, index) => Math.pow(x, index + 1)).reduce((a, b) => a + b, 0) == n
? "Disarium !!" : "Not !!"
}
[7 kyu] Maximum Triplet Sum (Array Series #7)
Task
Given an array/list [] of n integers , find maximum triplet sum in the array Without duplications .
Notes :
Array/list size is at least 3 .
Array/list numbers could be a mixture of positives , negatives and zeros .
Repetition of numbers in the array/list could occur , So (duplications are not included when summing).
Input >> Output Examples
1- maxTriSum ({3,2,6,8,2,3}) ==> return (17)
Explanation:
As the triplet that maximize the sum {6,8,3} in order , their sum is (17)
Note : duplications are not included when summing , (i.e) the numbers added only once .
翻译:
任务
给定一个由n个整数组成的数组/列表,在数组中找到最大三元组和。
笔记:
数组/列表大小至少为3。
数组/列表编号可以是正数、负数和零的混合。
数组/列表中的数字可能会重复,因此(求和时不包括重复)。
解:
function maxTriSum(numbers){
let arr = [...new Set(numbers)].sort((a, b) => b - a);
return arr[0] + arr[1] + arr[2];
}
[7 kyu] V A P O R C O D E
ASC Week 1 Challenge 4 (Medium #1)
Write a function that converts any sentence into a V A P O R W A V E sentence. a V A P O R W A V E sentence converts all the letters into uppercase, and adds 2 spaces between each letter (or special character) to create this V A P O R W A V E effect.
Note that spaces should be ignored in this case.
Examples
"Lets go to the movies" --> "L E T S G O T O T H E M O V I E S"
"Why isn't my code working?" --> "W H Y I S N ' T M Y C O D E W O R K I N G ?"
翻译:
编写一个函数,比较两个值,一个是数字,一个为字符串。如果它们是相同的字符(不管它们的数据类型如何),则返回true;如果不是,则返回false。
为了使这一挑战更加困难,并促使挑战者阅读有关强制的内容,我禁用了一些内置方法,包括.toString()、.jin()、.split()、parseInt和.Number()。
解:
function vaporcode(string) {
return Array.from(string.replace(/\s+/g, "").toUpperCase()).join(" ")
}
[7 kyu] esreveR
Write a function reverse which reverses a list (or in clojure's case, any list-like data structure)
(the dedicated builtin(s) functionalities are deactivated)
翻译:
写一个函数reverse来反转列表(或者在clojure的情况下,任何类似列表的数据结构)
(专用内置功能已停用)
解:
reverse = function(array) {
var newArr = [];
for (var i = array.length-1; i>=0; i--){
newArr.push(array[i]);
}
return newArr;
}
[8 kyu] Parse float
Write function parseF which takes an input and returns a number or null if conversion is not possible. The input can be one of many different types so be aware.
翻译:
编写函数parseF,它接受一个输入,如果转换不可能,则返回一个数字或null。输入可以是多种不同类型之一,因此请注意。
解:
function parseF(s) {
return isNaN(parseFloat(s)) ? null : parseFloat(s);
}