Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
var oldArray = [12, 45, 6, 23, 19, 20, 20, 15, 30, 42];
var newArray=[];
//var addFive=function(number){
//return number+5;
//};
//for (var i=0; i<oldArray.length; i++){
//  newArray.push(addFive(oldArray[i]));
//}
//console.log(newArray);
//var square = function(root){
//  return root*root;
//};
//for (var i=0; i <oldArray.length; i++){
//  newArray.push(square(oldArray[i]));
//}
//console.log(newArray);
//NOT OK index:4,5,8, 9 doesn't work
//var oddIndex = function(index){
//if (index % 2 ===1){  
//return (index*2);
//}
//else if(index % 2===0){
//  return index;
//}
//};
//for (var i=0; i<oldArray.length; i++){
//  newArray.push(oddIndex(oldArray[i]));
//}
//console.log(newArray);
for (var i=oldArray.length-1; i>=0; i-=1){
 newArray.push(oldArray[i]);
}
console.log(newArray);
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
magdalenabialonpro
0viewers