Created
July 31, 2024 01:29
-
-
Save momo-lab/1d5cf09ee7c4feb5b377957c4c186551 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 指定した条件の位置に値を追加する。合致しない場合は末尾に追加する。 | |
Array.prototype.insertIf = function(value, condition) { | |
const index = this.findIndex(condition); | |
if (index < 0) { | |
this.push(value); | |
} else { | |
this.splice(index, 0, value); | |
} | |
return this; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment