code.ashish.me

Atom feed

Recently added: 128 Longest Consecutive Sequence, 347 Top K Frequent Elements, 045 Jump Game 2, 228 Summary Ranges, 219 Contains Duplicate 2

11 Falsy Bouncer

/**
 * Created by Ashish Patel
 * Copyright © 2017 ashish.me
 * ashishsushilpatel@gmail.com 
 */

/**
 * Remove all falsy values from an array.
 * Falsy values in JavaScript are false, null, 0, "", undefined, and NaN.
 */

function bouncer(arr) {
    return arr.filter((item) => {
        return Boolean(item);
    });
  }
  
console.log(bouncer([7, "ate", "", false, 9]));

Created 2019-11-24T04:53:20+05:30 · Edit