Last active
March 27, 2017 18:18
-
-
Save ronaiza-cardoso/720cda408bbc899fc6c69bfddfbe6505 to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* Show Me the Evens - Show me the Odds | |
* Diana is learning to count and she just learned the difference between odds and even numbers. | |
* She wants to have some fun, so she picks a random number. | |
* If that number is even, she decides to count all the even numbers up to it starting from 0 up to (but not including) the input. | |
* If not, she decides to count all the odd numbers up to that number starting from 1 (but not including) the input. | |
**/ | |
function count(x) { | |
var numbers = []; | |
if (x % 2 === 0) { // check that x is even | |
for (var i = 0; i < x; i += 2) { // assign i to 0; give i the limit of x; and increment by 2 | |
numbers.push(i); | |
} | |
} else { | |
for (var j = 1; j < x; j += 2) { // assign i to 1; give i the limit of x; and increment by 2 | |
numbers.push(j); | |
} | |
} | |
return numbers; | |
} | |
/* ES6 */ | |
const count = x => { | |
if (x % 2 === 0) { | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
uhuhuhuuhhuhuhuhuhuhuhuhuhhuhuh funcional com Kotlin
val numbersPairsOdds = arrayOf(1, 3, 5, 6)
fun calc(x: Array<Int> = numbersPairsOdds) = x.map { if (it % 2 == 0) { print("número par -> $x , ") } else { print("número impar -> $x ") } }