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..

Discussion (1)

Collapse
laniltee profile image
Lanil Marasinghe • Edited on
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"]