DEV Community

k@k
k@k

Posted on

JavaScript Challenge #2

let array = ["hello.txt","hello.zip","","hello.exe"];

...........
...........
Output : [".txt",".zip","null",".exe"];

Understand the problem and solve it...make your solution on comments..

Top comments (1)

Collapse
 
laniltee profile image
Lanil Marasinghe • Edited
let extensions = array.map(fileNames => {
    let fileNameParams = fileNames.split(".");
    let extension = fileNameParams[fileNameParams.length - 1];
    return extension === "" ? "null" : `.${extension}`;
});

console.log(extensions); // => [".txt",".zip","null",".exe"]