Last active
September 1, 2019 22:05
-
-
Save pmolina/3bb4a81c6d7fb9551c730c76083eaa59 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
// *** 1 *** | |
var flavors = [ | |
{ | |
"id":1, | |
"name":"Chocolate" | |
}, | |
{ | |
"id":2, | |
"name":"Frutos del bosque" | |
}, | |
{ | |
"id":3, | |
"name":"Vainilla" | |
}, | |
{ | |
"id":4, | |
"name":"Tramontana" | |
} | |
]; | |
// *** 2 *** | |
for (var i in flavors) { | |
console.log(1 << flavors[i]["id"]); | |
} | |
// *** 3 *** | |
for (var i in flavors) { | |
console.log(1 << flavors[i]["id"] - 1); | |
} | |
// *** 4 *** | |
for (var i in flavors) { | |
console.log(flavors[i]["name"] + ": " + flavors[i]["id"] + " -> " + (1 << flavors[i]["id"] - 1).toString(2)); | |
} | |
// *** 5 *** | |
var db = 0; // Mi base de datos arranca en cero, no tiene ningún gusto. | |
db = db | 1 << (1 - 1); // Agrego que tengo Chocolate | |
db = db | 1 << (4 - 1); // Agrego que tengo Tramontana | |
console.log(db); | |
// *** 6 *** | |
db |= 1 << (2 - 1); // Agrego que entró Frutos del bosque | |
// *** 7 *** | |
db &= ~(1 << (1 - 1)); // Me quedé sin Chocolate |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment