DEV Community

loading...

Discussion on: JavaScript Coding Challenges

Collapse
mehdibenhemdene profile image
mehdibenhemdene

Suggested alternative solution for "Where do I belong" using Array.prototype.filter:

var array = [1, 2, 3, 4];

function getIndexToIns(arr, number) {
  let result = arr.sort().filter(el => el <= number).length;
  return result;
}

console.log(getIndexToIns(array, 8));
Collapse
mehdibenhemdene profile image
mehdibenhemdene

Also a simple "Destroyer" implementation:

function destroyer(arr, ...params) {
  return arr.filter(el=>!params.includes(el));
}