[+] Python range()

This commit is contained in:
Hykilpikonna
2021-12-10 23:02:21 -05:00
parent df1a49fe6f
commit f41e32970a
2 changed files with 24 additions and 4 deletions
+22
View File
@@ -0,0 +1,22 @@
/**
* Same as python's range
*
* Ways of calling this function:
* range(to)
* range(from, to)
* range(from, to, step)
*
* @param fromOrTo Either from or to. From is inclusive
* @param to to, Not inclusive
* @param step Step
*/
export function range(fromOrTo: number, to?: number, step = 1): number[]
{
const from = to ? fromOrTo : 0
to = to ? to : fromOrTo
return [...Array(Math.floor((to - from) / step))].map((_, i) => from + i * step);
}
console.log(range(3))
console.log(range(2, 5))
+2 -4
View File
@@ -20,6 +20,7 @@ import {Options, Vue} from 'vue-class-component';
import "vue3-colorpicker/style.css";
import {ColorPicker} from "vue3-colorpicker";
import {Color} from "three";
import {range} from "@/utils";
@Options({components: {ColorPicker}})
export default class MyColorPicker extends Vue
@@ -30,10 +31,7 @@ export default class MyColorPicker extends Vue
mounted(): void
{
this.palette.push(['', '', '', '', '', '', '', '', '', ''])
this.palette.push(['', '', '', '', '', '', '', '', '', ''])
this.palette.push(['', '', '', '', '', '', '', '', '', ''])
return
this.palette = range(3).map(_ => range(10).map(_ => ''))
}
change(color: string): void