{ "cells": [ { "cell_type": "markdown", "id": "f003b793-ddf5-43b7-b557-3c6961a12483", "metadata": {}, "source": [ "### Ce que nous voulons, une classe qui définit un match de dodgeball!" ] }, { "cell_type": "code", "execution_count": null, "id": "a72f5733-4c3f-4a81-95a7-4ff0f486c292", "metadata": {}, "outputs": [], "source": [ "\n", "// partie de dodgeball\n", "\n", "let players = [\"a\", \"b\", \"c\", \"d\", \"e\", \"f\"];\n", "\n", "function listeDeJoueurMorts(){}\n", "\n", "function listDeJoueur(){}\n", "\n", "function kill(nomDuJoueur){}\n", "\n", "function attrape(){}" ] }, { "cell_type": "markdown", "id": "84e2ee1c-d8f5-4145-be1c-2e3775e483ef", "metadata": {}, "source": [ "### Définission premiere classe" ] }, { "cell_type": "code", "execution_count": 2, "id": "b1a24c1a-f1f0-434d-b2d4-a8ddcf668047", "metadata": {}, "outputs": [], "source": [ "class Politicien {\n", "\n", "}\n", "\n", "const politicien = new Politicien();" ] }, { "cell_type": "markdown", "id": "9b2393ec-6ddd-4747-b47b-2a714cb2b7b1", "metadata": {}, "source": [ "### Classe avec méthode simple" ] }, { "cell_type": "code", "execution_count": 12, "id": "72649f7e-c5da-48d9-9e9a-846f084e9cf4", "metadata": {}, "outputs": [], "source": [ "class JackOfAllTrade{\n", " add(a, b){\n", " return a + b;\n", " }\n", "\n", " multiply(a, b){\n", " return a * b;\n", " }\n", "\n", " add1(x){\n", " return this.add(x, 1);\n", " }\n", "}" ] }, { "cell_type": "code", "execution_count": 13, "id": "a8c0005e-2fff-4f50-be35-4dd56bf669e2", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\u001b[33m199\u001b[39m" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "let joat = new JackOfAllTrade()\n", "joat.add(109, 90)" ] }, { "cell_type": "code", "execution_count": 14, "id": "f9c756be-ca43-458a-993d-67652cd5986a", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\u001b[33m101\u001b[39m" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "joat.add1(100)" ] }, { "cell_type": "code", "execution_count": 19, "id": "dda5b8a5-3f3d-40dc-9a02-ca38d970f2ec", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\u001b[32m\"hello_world foifoi\"\u001b[39m" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\n", "class ChangeCase{\n", " \n", " toSnake(str){\n", " str = str.replace(\" \", \"_\");\n", " return str;\n", " }\n", "\n", "}\n", "let case1 = new ChangeCase();\n", "case1.toSnake(\"hello world foifoi\");" ] }, { "cell_type": "code", "execution_count": 1, "id": "29783c57-bcd6-4522-97d7-6fda3bde0d19", "metadata": {}, "outputs": [], "source": [ "let s = \"bonjour monde\"" ] }, { "cell_type": "code", "execution_count": 2, "id": "6fc63875-819c-4d09-b661-90bbdd273f2c", "metadata": {}, "outputs": [], "source": [ "let idx = s.indexOf(\" \")" ] }, { "cell_type": "code", "execution_count": 3, "id": "22adb79c-4c67-45fd-929f-8be1ea3b1c83", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\u001b[32m\"bonjourmonde\"\u001b[39m" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s = s.replace(\" \", \"\")" ] }, { "cell_type": "code", "execution_count": 5, "id": "a7bf2d08-6a65-44de-8091-095135b57908", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\u001b[32m\"M\"\u001b[39m" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "s.substring(idx, idx + 1).toUpperCase()" ] }, { "cell_type": "code", "execution_count": null, "id": "8f64482f-2d87-4f0a-b579-050c0bbe477a", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Deno", "language": "typescript", "name": "deno" }, "language_info": { "file_extension": ".ts", "mimetype": "text/x.typescript", "name": "typescript", "nb_converter": "script", "pygments_lexer": "typescript", "version": "5.2.2" } }, "nbformat": 4, "nbformat_minor": 5 }