code.ashish.me

Atom feed

Recently added: 02 Count Of Subset Sum, 416 Partition Equal Subset Sum, 01 Subset Sum, 518 Coin Change 2, 983 Minimum Cost For Tickets

17 Finders Keeper

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

function findElement(arr, func) {
  let num = 0;
  for(let i = 0; i < arr.length; i++){
    num = arr[i];
    if(func(num)){
      return num;
    }
  }
  return undefined;
}

findElement([1, 2, 3, 4], num => num % 2 === 0);

Created 2019-11-24T04:41:20+05:18 · Edit