Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions solutions/javascript/lucky-numbers/1/lucky-numbers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// @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) {
const num1 = Number(array1.join(''));
const num2 = Number(array2.join(''));

return num1 + num2;

}

/**
* Checks whether a number is a palindrome.
*
* @param {number} value
* @returns {boolean} whether the number is a palindrome or not
*/
export function luckyNumber(value) {

const str = String(value);
const reversed = str.split('').reverse().join('');

return str === reversed;

}

/**
* 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){
return "Required field";
}

const num = Number(input);

if(!num ){
return "Must be a number besides 0";
}
const str = String(num);
const reversed = str.split('').reverse().join('');

return "";

}