JavaScript 寺子屋 24 / filter の説明動画
Tweet動画撮りました!
filter
describe("filter", () => {
const array = ["nakanishi", "john", "jimmy"];
it("all true", () => {
const res = array.filter(person => {
return true;
});
expect(res).toEqual(["nakanishi", "john", "jimmy"]);
});
it("all false", () => {
const res = array.filter(person => {
return false;
});
expect(res).toEqual([]);
});
it("naknishi", () => {
const res = array.filter(person => {
return person === "nakanishi";
});
expect(res).toEqual(["nakanishi"]);
});
it("length", () => {
const res = array.filter(person => {
return person.length > 4;
});
expect(res).toEqual(["nakanishi", "jimmy"]);
});
});
宿題
いろんな配列を作って、filter してみてください!自由に。
今日は以上です!