Skip to content

Instantly share code, notes, and snippets.

@ronaiza-cardoso
Last active March 27, 2017 18:18
Show Gist options
  • Save ronaiza-cardoso/720cda408bbc899fc6c69bfddfbe6505 to your computer and use it in GitHub Desktop.
Save ronaiza-cardoso/720cda408bbc899fc6c69bfddfbe6505 to your computer and use it in GitHub Desktop.
/**
* 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) {
@beatorizu
Copy link

function show_odd_even(number) {
  var numbers = [];
  for (var cont = verify_odd_even(number); cont < number; cont+=2) {
    numbers.push(cont);
  }
  return numbers;
}

function verify_odd_even(number) {
  if (number % 2 === 0) {
    return 0;
  }
  return 1;
}

@ihavenonickname
Copy link

ihavenonickname commented Mar 21, 2017

who needs readability anyway

const show = n => [...Array(Math.ceil(n / 2) - n % 2).keys()].map(x => x * 2 + n % 2);

also, OP's comment in line 16 is wrong.

@andersonFaro9
Copy link

andersonFaro9 commented Mar 27, 2017

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 ") } }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment