Last active
March 25, 2021 19:43
-
-
Save joshuaatencia/421c4e417055526e82cc21a012a4f4a3 to your computer and use it in GitHub Desktop.
function with diferent varial's type
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Combinable = number | string; | |
type ConversionDescriptor = 'as-number' | 'as-text'; | |
function combine(input1: Combinable, input2: Combinable, resultConversation: ConversionDescriptor){ | |
let result; | |
if(typeof input1 === 'number' && typeof input2 === 'number' || resultConversation === 'as-number'){ | |
result = +input1 + +input2; | |
}else{ | |
result = `${input1} ${input2}`; | |
} | |
return result; | |
} | |
const combinedStringAge = combine(12,14, 'as-number') | |
console.log(combinedStringAge); | |
const age = combine(12, 14, 'as-number'); | |
console.log(age) | |
const names = combine('Daniela', 'Romero', 'as-text'); | |
console.log(names) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment