Skip to content

Instantly share code, notes, and snippets.

@tak1827
Created December 9, 2018 05:00
Show Gist options
  • Save tak1827/a9ee11f41ce79f70ad1e7cdd7dd4b656 to your computer and use it in GitHub Desktop.
Save tak1827/a9ee11f41ce79f70ad1e7cdd7dd4b656 to your computer and use it in GitHub Desktop.
/***********
Discription
*************/
// Name: Takayuki Tamura
/***********
Text field
*************/
function test1(ary) {
let target;
for (let i = 0; i < ary.length - 3; i+=3) {
if(ary[i] !== ary[i+2]) {
target = i;
break;
}
}
return typeof target !== 'undefined'
? ary[target]
: ary[ary.length-1];
}
function test2(ary) {
let swp = new Array(ary.length);
for(let i = 0; i < ary.length; i+=4) {
if (typeof ary[i+2] !== 'undefined') {
swp[i] = ary[i+2];
swp[i+2] = ary[i];
} else if (typeof ary[i] !== 'undefined') {
swp[i] = ary[i];
}
if (typeof ary[i+3] !== 'undefined') {
swp[i+1] = ary[i+3];
swp[i+3] = ary[i+1];
} else if (typeof ary[i+1] !== 'undefined') {
swp[i+1] = ary[i+1];
}
}
return swp;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment