-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlucky-numbers.js
36 lines (32 loc) · 908 Bytes
/
lucky-numbers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// @ts-check
/**
* Calculates the sum of the two input arrays.
*
* @param {number[]} array1
* @param {number[]} array2
* @returns {number} sum of the two arrays
*/
export function twoSum(array1, array2) {
return parseInt(array1.join("")) + parseInt(array2.join(""));
}
/**
* Checks whether a number is a palindrome.
*
* @param {number} value
* @returns {boolean} whether the number is a palindrome or not
*/
export function luckyNumber(value) {
return value === parseInt(`${value}`.split("").reverse().join(""));
}
/**
* Determines the error message that should be shown to the user
* for the given input value.
*
* @param {string|null|undefined} input
* @returns {string} error message
*/
export function errorMessage(input) {
if (input == null || input === "") return "Required field";
if (!Number(input) || Number(input) == 0 ) return "Must be a number besides 0";
return "";
}