Snippets Collections
let clickMe = document.querySelector('button');

function getRandomNumber(min, max) {
  let totalEle = max - min + 1;
  let result = Math.floor(Math.random() * totalEle) + min;
  return result;
}
function createArrayOfNumber(start, end) {
  let myArray = [];
  for (let i = start; i <= end; i++) {
    myArray.push(i);
  }
  return myArray;
}
let numbersArray = createArrayOfNumber(1, 10);

clickMe.addEventListener('click', () => {
  if (numbersArray.length === 0) {
    console.log('No more random number');
    return;
  }
  let randomIndex = getRandomNumber(0, numbersArray.length - 1);
  let randomNumber = numbersArray[randomIndex];
  numbersArray.splice(randomIndex, 1);
  console.log(randomNumber);
});
let items = [1,25,"JavaScript",69,"css","34","keep coding","html"];
console.log(items)

//shuffle array
function shuffle(arr){
  for(let i =arr.length-1;i>0;i--){
    const j = Math.floor(Math.random() * (i+1));
    [arr[i],arr[j]] = [arr[j],arr[i]];
  }
  return arr
}
console.log(shuffle(items))

//shuffle selected index 
const  itemToShuffle = items.slice(3,7);
console.log(shuffle(itemToShuffle))

//items after shuffling item from index 3 to 7
items = [items[0],items[1],items[2],...itemToShuffle,items[7]]
console.log(items)
const arr = [333,1,2,11,22,3,4]
console.log(arr.sort())

arr.sort((a,b)=>a-b)

console.log(arr)
const arr = ["Apple",45,"","google",null],,,,"facebook","",69]

const removeEle = arr.filter((el)=> return el !=null && el != "")
function isEqual(arr1,arr2){
  let x = arr1.length;
  let y = arr2.lenght;
  
  //if lenght of array are not equal means array are not equal 
  if(x !=  y) return false;
  
  //sorting both array
  x.sort();
  y.sort();
  
  // Linearly compare elements
  for(let i=0;i<x;i++){
    if(x[i] != y[i]) return false
  }
  // If all elements were same.
    return true
}

let arrayOne = [3, 5, 2, 5, 2]
let arrayTwo = [2, 3, 5, 5, 2]

isEqual(arrayOne,arrayTwo) ? console.log("Matched") : console.log("Not Match")
$oneDimensionalArray = array_map('current', $twoDimensionalArray);

/*
current() function returns the value of the current element in an array. for ex : $fruits = array("banana", "apple", "orange"); echo current($fruits) //will return "banana" since current pointer is on index 0 which is banana
*/
 const arr = ["This", "Little", "Piggy"];
const first = arr.slice(0, 1);
const the_rest = arr.slice(1);console.log(first); // ["This"]
console.log(the_rest); // ["Little", "Piggy"]                               
                                
for (int i = 0; i < n; i++)
{
    if (valCount.ContainsKey(x))
        valCount[x]++;
    else
        valCount[x] = 1;
}
itemList.stream()
          .filter(item -> item.getPropertyList()
                         .stream().anyMatch(property -> property.getKey().equals("Test")))
           .collect(Collectors.toList());
star

Fri Apr 16 2021 07:42:52 GMT+0000 (UTC) https://playcode.io/757523/

#javascript #array #random #randomarray #dom
star

Thu Apr 08 2021 10:16:24 GMT+0000 (UTC) https://playcode.io/754960/

#javascript #array #shuffle
star

Fri Apr 02 2021 08:01:12 GMT+0000 (UTC)

#javascript #array #sort
star

Fri Apr 02 2021 06:52:39 GMT+0000 (UTC)

#javascript #array
star

Mon Nov 30 2020 14:23:00 GMT+0000 (UTC) https://stackoverflow.com/questions/8754980/how-to-convert-two-dimensional-array-to-one-dimensional-array-in-php5

#php #array
star

Fri Apr 24 2020 11:44:23 GMT+0000 (UTC) https://css-tricks.com/snippets/javascript/getting-first-and-last-items-in-array-and-splitting-all-the-rest/

#css #css #items #array
star

Wed Apr 01 2020 08:37:24 GMT+0000 (UTC) https://stackoverflow.com/questions/60966491/how-to-clear-item-not-input-when-count-frequency-use-dictionary-c-sharp

#C# #c# #array #dictionary
star

Wed Apr 01 2020 08:28:49 GMT+0000 (UTC) https://stackoverflow.com/questions/60966469/how-to-find-an-element-in-array-of-object-with-streams

#java #java #stream #array

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension