DEV Community

Discussion on: Daily Challenge #293 - Name the Operations

Collapse
 
_bkeren profile image
''

JS

const nameOp = stringList => {

 const numList = stringList.split(" ").map(x => +x)
 const _nameOp = (numberList, result= "") => {
   if(numberList.length < 3) return result
   const op = `${numberList[0] + numberList[1] == numberList[2] ? 'addition' : numberList[0] - numberList[1] == numberList[2] ? 'subtraction' : numberList[0] * numberList[1] == numberList[2] ? 'multiplication' : 'division'},`
   return _nameOp(numberList.slice(1),`${result}${op}`)
 }

 return _nameOp(numList).slice(0,-1)
}