[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 !!"
翻譯:
給定一個數(shù)字,確定它是否為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 .
翻譯:
任務(wù)
給定一個由n個整數(shù)組成的數(shù)組/列表,在數(shù)組中找到最大三元組和。
筆記:
數(shù)組/列表大小至少為3。
數(shù)組/列表編號可以是正數(shù)、負(fù)數(shù)和零的混合。
數(shù)組/列表中的數(shù)字可能會重復(fù),因此(求和時不包括重復(fù))。
解:
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 ?"
翻譯:
編寫一個函數(shù),比較兩個值,一個是數(shù)字,一個為字符串。如果它們是相同的字符(不管它們的數(shù)據(jù)類型如何),則返回true;如果不是,則返回false。
為了使這一挑戰(zhàn)更加困難,并促使挑戰(zhàn)者閱讀有關(guān)強(qiáng)制的內(nèi)容,我禁用了一些內(nèi)置方法,包括.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)
翻譯:
寫一個函數(shù)reverse來反轉(zhuǎn)列表(或者在clojure的情況下,任何類似列表的數(shù)據(jù)結(jié)構(gòu))
(專用內(nèi)置功能已停用)
解:
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.
翻譯:
編寫函數(shù)parseF,它接受一個輸入,如果轉(zhuǎn)換不可能,則返回一個數(shù)字或null。輸入可以是多種不同類型之一,因此請注意。
解:
function parseF(s) {
return isNaN(parseFloat(s)) ? null : parseFloat(s);
}