Created
August 21, 2018 10:35
-
-
Save DanielRamosAcosta/0b8bc13adce4dbd1535aa234ee6b6e87 to your computer and use it in GitHub Desktop.
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
| function removeDecimalNumbers([ head, ...tail ]) { | |
| if (!head) return [] | |
| return Number.isInteger(head) | |
| ? [head, ...removeDecimalNumbers(tail)] | |
| : removeDecimalNumbers(tail) | |
| } | |
| module.exports = { | |
| removeDecimalNumbers | |
| } |
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
| function removeDecimalNumbers(numberArr) { | |
| if (numberArr.length <= 0) { | |
| return [] | |
| } | |
| let firstElement = numberArr[0] | |
| let restElements = numberArr.slice(1, numberArr.length) | |
| const withoutDecimals = removeDecimalNumbers(restElements) | |
| if (Number.isInteger(firstElement)) { | |
| return [firstElement].concat(withoutDecimals) | |
| } else { | |
| return withoutDecimals | |
| } | |
| } | |
| module.exports = { | |
| removeDecimalNumbers | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment