Skip to content

Instantly share code, notes, and snippets.

@Jiert
Created August 25, 2015 04:38
Show Gist options
  • Save Jiert/6d42d1322336b52c3e52 to your computer and use it in GitHub Desktop.
Save Jiert/6d42d1322336b52c3e52 to your computer and use it in GitHub Desktop.
An interview test: Convert a string "1234" into an integer 1234 without using parseInt or Number
function converter(st){
var arrSt = st.split(''),
arrInt = [];
for (var i = 0; i < arrSt.length; i++){
arrInt.push(arrSt[i].charCodeAt() - 48);
}
// loop over arry again
var counter = 0, num;
for (var j = 0; j < arrInt.length; j++ ){
num = Math.pow(10, arrInt.length - j - 1 );
counter += arrInt[j] * num;
}
return counter;
}
@Jiert
Copy link
Author

Jiert commented Aug 25, 2015

This is just stupid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment