Last active
September 12, 2018 10:44
-
-
Save ultim8k/9e375fef439c3e241a7ad930f073b862 to your computer and use it in GitHub Desktop.
delete values from array | not optimised - who cares
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var valuesToBeDeleted = [1, 5, 7, 15]; | |
var mixedValues = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]; | |
// Boring solution: | |
valuesToBeDeleted.forEach(item => { | |
var itemIndex = mixedValues.indexOf(item); | |
mixedValues.splice(itemIndex, 1); | |
}); | |
// Better solution: | |
var cleanValues = mixedValues.filter(item => valuesToBeDeleted.indexOf(item) < 0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment