Which of the two is more efficient. Assuming I have this,
uint[] public availableRooms = [1,2,3,4,5,6,7];
And I need to know whether 5 is present in the array above. Which of the two is more efficient and can you help with how to do that with mapping?
Edit.
Based on the comments by users, a mapping will be the best way to find out if an element exists or not. So I changed the code into something like this
mapping (uni256 => bool);
And in the constructor function, I constructor all instances of my availableRooms
constructor (){
availableRooms[1] = true;
availableRooms[2] = true;
availableRooms[3] = true;
availableRooms[4] = true;
availableRooms[5] = true;
availableRooms[6] = true;
availableRooms[7] = true;
}
And now to find out if the room really exist, all I have to do is
availableRooms[5] ;