Answers for "to put dash between two even numbers in number"

0

to put dash between two even numbers in number

function insertHyphen(str) {
  var strArr = str.split('');
  var numArr = strArr.map(Number);
  for(var i = 0; i < numArr.length; i++) {
   if(numArr[i-1]%2===0 && numArr[i]%2===0) {
        numArr.push('-');
    }
  }
  return numArr.join('');
}
insertHyphen('112233445566'); // 112233445566---
Posted by: Guest on May-02-2020
0

to put dash between two even numbers in number

function insertHyphen(str) {
  var strArr = str.split('');
  var numArr = strArr.map(Number);
  for(var i = 0; i < numArr.length; i++) {
   if(numArr[i-1]%2===0 && numArr[i]%2===0) {
        numArr.push('-');
    }
  }
  return numArr.join('');
}
insertHyphen('112233445566'); // 112233445566---
Posted by: Guest on May-02-2020

Code answers related to "to put dash between two even numbers in number"

Code answers related to "Javascript"

Browse Popular Code Answers by Language