Skip to main content

Command Palette

Search for a command to run...

Array tit-bits

Updated
β€’1 min readβ€’View as Markdown
Array tit-bits
N

I am a self taught web developer owning experience of 12+ years in web development field.

1. Know it's an array or not

const points = [23, 3, 89, 98, 40]
// Before 😏
console.log(points.length)
// it returns true

// After πŸ‘Œ
console.log(Array.isArray(points))
// it returns true

2. Get last element of an array

const points = [23, 3, 89, 98, 40]
// Before 😏
console.log(points[points.length - 1])
// it returns 40

// After πŸ‘Œ
console.log(points.at(-1))
// it returns 40

3. Count occurrences in an array

const occurencies = (arr) => 
     arr.reduce((a, v) => {
      a[v] = a[v] ? a[v] + 1 : 1;
      return a;
     }, {});

occurencies(['a', 'b', 'a', 'c', 'a',  'a', 'b'])
// {a: 4, b: 2, c: 1}

occurencies([...'soccer'])
// {s: 1, o: 1, c: 2, r: 1}
D
dy can4y ago

snake game is a good and amusing snake-themed game that is suited for gamers of all ages! When playing snakes, you must move your snake to consume white areas in order to grow up. You must also avoid collisions when playing snakes.

D
dy can4y ago

<a href="https://snake-game.co">snake game</a> is a good and amusing snake-themed game that is suited for gamers of all ages! When playing snakes, you must move your snake to consume white areas in order to grow up. You must also avoid collisions when playing snakes.

L
Lado Nna4y ago

Take advantage of your leisure time by exploring the world of colourful head beads. LOL Beans is an online multiplayer campaign game that has gone popular. Thousands of players battle for the title of champion in hundreds of stadiums throughout the world.

More from this blog

W

Web Chronicles

12 posts

I'm a Senior Full Stack Developer with 10+ years of experience. I strive to be a humble team player and be approachable to receive and give feedback.