
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Convert Array of Decimal Strings to Array of Integer Strings in JavaScript
We are required to write a JavaScript function that takes in an array of decimal strings. The function should return an array of strings of integers obtained by flooring the original corresponding decimal values of the array.
For example, If the input array is −
const input = ["1.00","-2.5","5.33333","8.984563"];
Then the output should be −
const output = ["1","-2","5","8"];
Example
The code for this will be −
const input = ["1.00","-2.5","5.33333","8.984563"]; const roundIntegers = arr => { const res = []; arr.forEach((el, ind) => { const strNum = String(el); res[ind] = parseInt(strNum); }); return res; }; console.log(roundIntegers(input));
Output
The output in the console −
[ 1, -2, 5, 8 ]
Advertisements