Created
March 10, 2019 19:58
-
-
Save rupesx26/51ec8baa7e911dc0f62b0efa4553c1ac to your computer and use it in GitHub Desktop.
filter func() for Odd/Even, string separation
This file contains 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
let vals = [1,2,3,4,5,6,7,8,9] | |
let newVals =[] | |
newVals.push.apply(newVals, vals); | |
let newValsOdd = [] | |
newValsOdd.push.apply(newValsOdd, vals); | |
function isEven (num) { | |
return (num % 2 === 0) | |
} | |
vals = vals.filter(isEven) | |
console.log('method1',vals) | |
newVals = newVals.filter(x => (x % 2 == 0)) | |
console.log('method 2', newVals) | |
newValsOdd = newValsOdd.filter(x => (x % 2 == 1)) | |
console.log('method 3', newValsOdd) | |
let text = "Hey, You are doing good code today." | |
let word = text.split(/\W+/); | |
console.log(word) | |
//but we get the empty string after last word, then how to remove it? | |
let word2 = text.split(/\W+/).filter(x=>x.length) | |
console.log(word2) | |
// OR we can get what we want | |
let word3 = text.split(/\W+/).filter(x=>x.length >=4) | |
console.log(word3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment