JSFiddle - React, Tailwind, and code Playground
by jaygiri
JavaScript
[ 1, 2, 2, 3, 3 ] => 1
[ 1, 1, 2, 2, 2 ] => 2
function getOdds(arr) {
var result = [];
for(var i=0, l = arr.length; i<l; i++) {
var item = arr[i],
index = result.indexOf(item);
if ( index < 0) {
result.push(item);
} else {
delete(result[index]);
}
}
return result;
}
[]
[1]
{}
null
"abc"
true
false
Infinite
["acd", "xyz"]
undefined
/** Dack ***/
function Card(type, value){
this.type = type;
this.value = value;
return this;
}
Card.prototype.toString = fuction(){
// build the text describing the card.
}
function Deck(){
this.cards = [];
this.shuffle();
return this;
}
Dack.prototype.shuffle = function(){
this.cards = [];
function getSet() {
for(var i = 0; i < 12; i++) {
var c = new Card(type, i);
}
}
this.cards.concat(getSet(0)).concat(getSet(1)).concat(getSet(2)).concat(getSet(3));
}
Deck.prototype.deal = function(){
function getRandomeValue(){
return Math.randome(0, 51);
}
var index, card = null;
while (!card && this.cards.length) {
index = getRandomeValue();
card = this.cards[index];
}
delete(this.cards[index]);
return card;
}
var d = new Dack();
var c = d.deal();